blob: 1a9d90ab666bf2b2e73e64ee1d05b4d24401cffb [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 Piepho51f0b8d52009-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 Piepho51f0b8d52009-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 Verkuilaecde8b52008-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;
431
432 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
433 "bytesused=%d, flags=0x%08d, "
434 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
435 p->timestamp.tv_sec / 3600,
436 (int)(p->timestamp.tv_sec / 60) % 60,
437 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300438 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300439 p->index,
440 prt_names(p->type, v4l2_type_names),
441 p->bytesused, p->flags,
442 p->field, p->sequence,
443 prt_names(p->memory, v4l2_memory_names),
444 p->m.userptr, p->length);
445 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
446 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
447 tc->hours, tc->minutes, tc->seconds,
448 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
449}
450
451static inline void dbgrect(struct video_device *vfd, char *s,
452 struct v4l2_rect *r)
453{
454 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
455 r->width, r->height);
456};
457
458static inline void v4l_print_pix_fmt(struct video_device *vfd,
459 struct v4l2_pix_format *fmt)
460{
461 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
462 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
463 fmt->width, fmt->height,
464 (fmt->pixelformat & 0xff),
465 (fmt->pixelformat >> 8) & 0xff,
466 (fmt->pixelformat >> 16) & 0xff,
467 (fmt->pixelformat >> 24) & 0xff,
468 prt_names(fmt->field, v4l2_field_names),
469 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
470};
471
472static inline void v4l_print_ext_ctrls(unsigned int cmd,
473 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
474{
475 __u32 i;
476
477 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
478 return;
479 dbgarg(cmd, "");
480 printk(KERN_CONT "class=0x%x", c->ctrl_class);
481 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300482 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300483 printk(KERN_CONT " id/val=0x%x/0x%x",
484 c->controls[i].id, c->controls[i].value);
485 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300486 printk(KERN_CONT " id=0x%x,size=%u",
487 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300488 }
489 printk(KERN_CONT "\n");
490};
491
492static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
493{
494 __u32 i;
495
496 /* zero the reserved fields */
497 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300498 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300499 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300500
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300501 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
502 when using extended controls.
503 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
504 is it allowed for backwards compatibility.
505 */
506 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
507 return 0;
508 /* Check that all controls are from the same control class. */
509 for (i = 0; i < c->count; i++) {
510 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
511 c->error_idx = i;
512 return 0;
513 }
514 }
515 return 1;
516}
517
Hans Verkuila3998102008-07-21 02:57:38 -0300518static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300519{
Hans Verkuila3998102008-07-21 02:57:38 -0300520 if (ops == NULL)
521 return -EINVAL;
522
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300523 switch (type) {
524 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300525 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300526 return 0;
527 break;
528 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300529 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300530 return 0;
531 break;
532 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300533 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300534 return 0;
535 break;
536 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300537 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300538 return 0;
539 break;
540 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300541 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300542 return 0;
543 break;
544 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300545 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300546 return 0;
547 break;
548 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300549 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300550 return 0;
551 break;
552 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300553 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300554 return 0;
555 break;
556 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300557 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300558 return 0;
559 break;
560 }
561 return -EINVAL;
562}
563
Hans Verkuil069b7472008-12-30 07:04:34 -0300564static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300565 unsigned int cmd, void *arg)
566{
567 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300568 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300569 void *fh = file->private_data;
Hans Verkuil069b7472008-12-30 07:04:34 -0300570 long ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300571
Hans Verkuil6a717882010-04-06 15:56:08 -0300572 if (ops == NULL) {
573 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
574 vfd->name);
575 return -EINVAL;
576 }
577
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300578 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
579 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
580 v4l_print_ioctl(vfd->name, cmd);
581 printk(KERN_CONT "\n");
582 }
583
Hans Verkuil6a717882010-04-06 15:56:08 -0300584 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300585
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300586 /* --- capabilities ------------------------------------------ */
587 case VIDIOC_QUERYCAP:
588 {
589 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300590
Hans Verkuila3998102008-07-21 02:57:38 -0300591 if (!ops->vidioc_querycap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300592 break;
593
Hans Verkuila3998102008-07-21 02:57:38 -0300594 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300595 if (!ret)
596 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
597 "version=0x%08x, "
598 "capabilities=0x%08x\n",
599 cap->driver, cap->card, cap->bus_info,
600 cap->version,
601 cap->capabilities);
602 break;
603 }
604
605 /* --- priority ------------------------------------------ */
606 case VIDIOC_G_PRIORITY:
607 {
608 enum v4l2_priority *p = arg;
609
Hans Verkuila3998102008-07-21 02:57:38 -0300610 if (!ops->vidioc_g_priority)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300611 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300612 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300613 if (!ret)
614 dbgarg(cmd, "priority is %d\n", *p);
615 break;
616 }
617 case VIDIOC_S_PRIORITY:
618 {
619 enum v4l2_priority *p = arg;
620
Hans Verkuila3998102008-07-21 02:57:38 -0300621 if (!ops->vidioc_s_priority)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300622 break;
623 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuila3998102008-07-21 02:57:38 -0300624 ret = ops->vidioc_s_priority(file, fh, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300625 break;
626 }
627
628 /* --- capture ioctls ---------------------------------------- */
629 case VIDIOC_ENUM_FMT:
630 {
631 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300632
Trent Piepho19c96e42009-03-04 01:21:02 -0300633 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300634 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300635 if (ops->vidioc_enum_fmt_vid_cap)
636 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300637 break;
638 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300639 if (ops->vidioc_enum_fmt_vid_overlay)
640 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300641 fh, f);
642 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300643 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300644 if (ops->vidioc_enum_fmt_vid_out)
645 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300646 break;
647 case V4L2_BUF_TYPE_PRIVATE:
Hans Verkuila3998102008-07-21 02:57:38 -0300648 if (ops->vidioc_enum_fmt_type_private)
649 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300650 fh, f);
651 break;
652 default:
653 break;
654 }
655 if (!ret)
656 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
657 "pixelformat=%c%c%c%c, description='%s'\n",
658 f->index, f->type, f->flags,
659 (f->pixelformat & 0xff),
660 (f->pixelformat >> 8) & 0xff,
661 (f->pixelformat >> 16) & 0xff,
662 (f->pixelformat >> 24) & 0xff,
663 f->description);
664 break;
665 }
666 case VIDIOC_G_FMT:
667 {
668 struct v4l2_format *f = (struct v4l2_format *)arg;
669
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300670 /* FIXME: Should be one dump per type */
671 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
672
673 switch (f->type) {
674 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300675 if (ops->vidioc_g_fmt_vid_cap)
676 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300677 if (!ret)
678 v4l_print_pix_fmt(vfd, &f->fmt.pix);
679 break;
680 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300681 if (ops->vidioc_g_fmt_vid_overlay)
682 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300683 fh, f);
684 break;
685 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300686 if (ops->vidioc_g_fmt_vid_out)
687 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300688 if (!ret)
689 v4l_print_pix_fmt(vfd, &f->fmt.pix);
690 break;
691 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300692 if (ops->vidioc_g_fmt_vid_out_overlay)
693 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300694 fh, f);
695 break;
696 case V4L2_BUF_TYPE_VBI_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300697 if (ops->vidioc_g_fmt_vbi_cap)
698 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300699 break;
700 case V4L2_BUF_TYPE_VBI_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300701 if (ops->vidioc_g_fmt_vbi_out)
702 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300703 break;
704 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300705 if (ops->vidioc_g_fmt_sliced_vbi_cap)
706 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300707 fh, f);
708 break;
709 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300710 if (ops->vidioc_g_fmt_sliced_vbi_out)
711 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300712 fh, f);
713 break;
714 case V4L2_BUF_TYPE_PRIVATE:
Hans Verkuila3998102008-07-21 02:57:38 -0300715 if (ops->vidioc_g_fmt_type_private)
716 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300717 fh, f);
718 break;
719 }
720
721 break;
722 }
723 case VIDIOC_S_FMT:
724 {
725 struct v4l2_format *f = (struct v4l2_format *)arg;
726
727 /* FIXME: Should be one dump per type */
728 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
729
730 switch (f->type) {
731 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300732 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300733 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300734 if (ops->vidioc_s_fmt_vid_cap)
735 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300736 break;
737 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300738 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300739 if (ops->vidioc_s_fmt_vid_overlay)
740 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300741 fh, f);
742 break;
743 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300744 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300745 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300746 if (ops->vidioc_s_fmt_vid_out)
747 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300748 break;
749 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300750 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300751 if (ops->vidioc_s_fmt_vid_out_overlay)
752 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300753 fh, f);
754 break;
755 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300756 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300757 if (ops->vidioc_s_fmt_vbi_cap)
758 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300759 break;
760 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300761 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300762 if (ops->vidioc_s_fmt_vbi_out)
763 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300764 break;
765 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300766 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300767 if (ops->vidioc_s_fmt_sliced_vbi_cap)
768 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300769 fh, f);
770 break;
771 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300772 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300773 if (ops->vidioc_s_fmt_sliced_vbi_out)
774 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300775 fh, f);
776 break;
777 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300778 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Hans Verkuila3998102008-07-21 02:57:38 -0300779 if (ops->vidioc_s_fmt_type_private)
780 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300781 fh, f);
782 break;
783 }
784 break;
785 }
786 case VIDIOC_TRY_FMT:
787 {
788 struct v4l2_format *f = (struct v4l2_format *)arg;
789
790 /* FIXME: Should be one dump per type */
791 dbgarg(cmd, "type=%s\n", prt_names(f->type,
792 v4l2_type_names));
793 switch (f->type) {
794 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300795 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300796 if (ops->vidioc_try_fmt_vid_cap)
797 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300798 if (!ret)
799 v4l_print_pix_fmt(vfd, &f->fmt.pix);
800 break;
801 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300802 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300803 if (ops->vidioc_try_fmt_vid_overlay)
804 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300805 fh, f);
806 break;
807 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300808 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300809 if (ops->vidioc_try_fmt_vid_out)
810 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300811 if (!ret)
812 v4l_print_pix_fmt(vfd, &f->fmt.pix);
813 break;
814 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300815 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300816 if (ops->vidioc_try_fmt_vid_out_overlay)
817 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300818 fh, f);
819 break;
820 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300821 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300822 if (ops->vidioc_try_fmt_vbi_cap)
823 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300824 break;
825 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300826 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300827 if (ops->vidioc_try_fmt_vbi_out)
828 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300829 break;
830 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300831 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300832 if (ops->vidioc_try_fmt_sliced_vbi_cap)
833 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300834 fh, f);
835 break;
836 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300837 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300838 if (ops->vidioc_try_fmt_sliced_vbi_out)
839 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300840 fh, f);
841 break;
842 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300843 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Hans Verkuila3998102008-07-21 02:57:38 -0300844 if (ops->vidioc_try_fmt_type_private)
845 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300846 fh, f);
847 break;
848 }
849
850 break;
851 }
852 /* FIXME: Those buf reqs could be handled here,
853 with some changes on videobuf to allow its header to be included at
854 videodev2.h or being merged at videodev2.
855 */
856 case VIDIOC_REQBUFS:
857 {
858 struct v4l2_requestbuffers *p = arg;
859
Hans Verkuila3998102008-07-21 02:57:38 -0300860 if (!ops->vidioc_reqbufs)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300861 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300862 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300863 if (ret)
864 break;
865
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300866 if (p->type < V4L2_BUF_TYPE_PRIVATE)
867 CLEAR_AFTER_FIELD(p, memory);
868
Hans Verkuila3998102008-07-21 02:57:38 -0300869 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300870 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
871 p->count,
872 prt_names(p->type, v4l2_type_names),
873 prt_names(p->memory, v4l2_memory_names));
874 break;
875 }
876 case VIDIOC_QUERYBUF:
877 {
878 struct v4l2_buffer *p = arg;
879
Hans Verkuila3998102008-07-21 02:57:38 -0300880 if (!ops->vidioc_querybuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300881 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300882 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300883 if (ret)
884 break;
885
Hans Verkuila3998102008-07-21 02:57:38 -0300886 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300887 if (!ret)
888 dbgbuf(cmd, vfd, p);
889 break;
890 }
891 case VIDIOC_QBUF:
892 {
893 struct v4l2_buffer *p = arg;
894
Hans Verkuila3998102008-07-21 02:57:38 -0300895 if (!ops->vidioc_qbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300896 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300897 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300898 if (ret)
899 break;
900
Hans Verkuila3998102008-07-21 02:57:38 -0300901 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300902 if (!ret)
903 dbgbuf(cmd, vfd, p);
904 break;
905 }
906 case VIDIOC_DQBUF:
907 {
908 struct v4l2_buffer *p = arg;
909
Hans Verkuila3998102008-07-21 02:57:38 -0300910 if (!ops->vidioc_dqbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300911 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300912 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300913 if (ret)
914 break;
915
Hans Verkuila3998102008-07-21 02:57:38 -0300916 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300917 if (!ret)
918 dbgbuf(cmd, vfd, p);
919 break;
920 }
921 case VIDIOC_OVERLAY:
922 {
923 int *i = arg;
924
Hans Verkuila3998102008-07-21 02:57:38 -0300925 if (!ops->vidioc_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300926 break;
927 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -0300928 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300929 break;
930 }
931 case VIDIOC_G_FBUF:
932 {
933 struct v4l2_framebuffer *p = arg;
934
Hans Verkuila3998102008-07-21 02:57:38 -0300935 if (!ops->vidioc_g_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300936 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300937 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300938 if (!ret) {
939 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
940 p->capability, p->flags,
941 (unsigned long)p->base);
942 v4l_print_pix_fmt(vfd, &p->fmt);
943 }
944 break;
945 }
946 case VIDIOC_S_FBUF:
947 {
948 struct v4l2_framebuffer *p = arg;
949
Hans Verkuila3998102008-07-21 02:57:38 -0300950 if (!ops->vidioc_s_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300951 break;
952 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
953 p->capability, p->flags, (unsigned long)p->base);
954 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -0300955 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300956 break;
957 }
958 case VIDIOC_STREAMON:
959 {
960 enum v4l2_buf_type i = *(int *)arg;
961
Hans Verkuila3998102008-07-21 02:57:38 -0300962 if (!ops->vidioc_streamon)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300963 break;
964 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -0300965 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300966 break;
967 }
968 case VIDIOC_STREAMOFF:
969 {
970 enum v4l2_buf_type i = *(int *)arg;
971
Hans Verkuila3998102008-07-21 02:57:38 -0300972 if (!ops->vidioc_streamoff)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300973 break;
974 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -0300975 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300976 break;
977 }
978 /* ---------- tv norms ---------- */
979 case VIDIOC_ENUMSTD:
980 {
981 struct v4l2_standard *p = arg;
982 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
983 unsigned int index = p->index, i, j = 0;
984 const char *descr = "";
985
986 /* Return norm array in a canonical way */
987 for (i = 0; i <= index && id; i++) {
988 /* last std value in the standards array is 0, so this
989 while always ends there since (id & 0) == 0. */
990 while ((id & standards[j].std) != standards[j].std)
991 j++;
992 curr_id = standards[j].std;
993 descr = standards[j].descr;
994 j++;
995 if (curr_id == 0)
996 break;
997 if (curr_id != V4L2_STD_PAL &&
998 curr_id != V4L2_STD_SECAM &&
999 curr_id != V4L2_STD_NTSC)
1000 id &= ~curr_id;
1001 }
1002 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001003 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001004
1005 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001006
1007 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1008 "framelines=%d\n", p->index,
1009 (unsigned long long)p->id, p->name,
1010 p->frameperiod.numerator,
1011 p->frameperiod.denominator,
1012 p->framelines);
1013
1014 ret = 0;
1015 break;
1016 }
1017 case VIDIOC_G_STD:
1018 {
1019 v4l2_std_id *id = arg;
1020
1021 ret = 0;
1022 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001023 if (ops->vidioc_g_std)
1024 ret = ops->vidioc_g_std(file, fh, id);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001025 else if (vfd->current_norm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001026 *id = vfd->current_norm;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001027 else
1028 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001029
1030 if (!ret)
1031 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1032 break;
1033 }
1034 case VIDIOC_S_STD:
1035 {
1036 v4l2_std_id *id = arg, norm;
1037
1038 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1039
1040 norm = (*id) & vfd->tvnorms;
1041 if (vfd->tvnorms && !norm) /* Check if std is supported */
1042 break;
1043
1044 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001045 if (ops->vidioc_s_std)
1046 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001047 else
1048 ret = -EINVAL;
1049
1050 /* Updates standard information */
1051 if (ret >= 0)
1052 vfd->current_norm = norm;
1053 break;
1054 }
1055 case VIDIOC_QUERYSTD:
1056 {
1057 v4l2_std_id *p = arg;
1058
Hans Verkuila3998102008-07-21 02:57:38 -03001059 if (!ops->vidioc_querystd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001060 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001061 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001062 if (!ret)
1063 dbgarg(cmd, "detected std=%08Lx\n",
1064 (unsigned long long)*p);
1065 break;
1066 }
1067 /* ------ input switching ---------- */
1068 /* FIXME: Inputs can be handled inside videodev2 */
1069 case VIDIOC_ENUMINPUT:
1070 {
1071 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001072
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001073 /*
1074 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1075 * CAP_STD here based on ioctl handler provided by the
1076 * driver. If the driver doesn't support these
1077 * for a specific input, it must override these flags.
1078 */
1079 if (ops->vidioc_s_std)
1080 p->capabilities |= V4L2_IN_CAP_STD;
1081 if (ops->vidioc_s_dv_preset)
1082 p->capabilities |= V4L2_IN_CAP_PRESETS;
1083 if (ops->vidioc_s_dv_timings)
1084 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1085
Hans Verkuila3998102008-07-21 02:57:38 -03001086 if (!ops->vidioc_enum_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001087 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001088
Hans Verkuila3998102008-07-21 02:57:38 -03001089 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001090 if (!ret)
1091 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1092 "audioset=%d, "
1093 "tuner=%d, std=%08Lx, status=%d\n",
1094 p->index, p->name, p->type, p->audioset,
1095 p->tuner,
1096 (unsigned long long)p->std,
1097 p->status);
1098 break;
1099 }
1100 case VIDIOC_G_INPUT:
1101 {
1102 unsigned int *i = arg;
1103
Hans Verkuila3998102008-07-21 02:57:38 -03001104 if (!ops->vidioc_g_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001105 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001106 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001107 if (!ret)
1108 dbgarg(cmd, "value=%d\n", *i);
1109 break;
1110 }
1111 case VIDIOC_S_INPUT:
1112 {
1113 unsigned int *i = arg;
1114
Hans Verkuila3998102008-07-21 02:57:38 -03001115 if (!ops->vidioc_s_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001116 break;
1117 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001118 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001119 break;
1120 }
1121
1122 /* ------ output switching ---------- */
1123 case VIDIOC_ENUMOUTPUT:
1124 {
1125 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001126
Hans Verkuila3998102008-07-21 02:57:38 -03001127 if (!ops->vidioc_enum_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001128 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001129
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001130 /*
1131 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1132 * CAP_STD here based on ioctl handler provided by the
1133 * driver. If the driver doesn't support these
1134 * for a specific output, it must override these flags.
1135 */
1136 if (ops->vidioc_s_std)
1137 p->capabilities |= V4L2_OUT_CAP_STD;
1138 if (ops->vidioc_s_dv_preset)
1139 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1140 if (ops->vidioc_s_dv_timings)
1141 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1142
Hans Verkuila3998102008-07-21 02:57:38 -03001143 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001144 if (!ret)
1145 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1146 "audioset=0x%x, "
1147 "modulator=%d, std=0x%08Lx\n",
1148 p->index, p->name, p->type, p->audioset,
1149 p->modulator, (unsigned long long)p->std);
1150 break;
1151 }
1152 case VIDIOC_G_OUTPUT:
1153 {
1154 unsigned int *i = arg;
1155
Hans Verkuila3998102008-07-21 02:57:38 -03001156 if (!ops->vidioc_g_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001157 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001158 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001159 if (!ret)
1160 dbgarg(cmd, "value=%d\n", *i);
1161 break;
1162 }
1163 case VIDIOC_S_OUTPUT:
1164 {
1165 unsigned int *i = arg;
1166
Hans Verkuila3998102008-07-21 02:57:38 -03001167 if (!ops->vidioc_s_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001168 break;
1169 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001170 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001171 break;
1172 }
1173
1174 /* --- controls ---------------------------------------------- */
1175 case VIDIOC_QUERYCTRL:
1176 {
1177 struct v4l2_queryctrl *p = arg;
1178
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001179 if (vfd->ctrl_handler)
1180 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1181 else if (ops->vidioc_queryctrl)
1182 ret = ops->vidioc_queryctrl(file, fh, p);
1183 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001184 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001185 if (!ret)
1186 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1187 "step=%d, default=%d, flags=0x%08x\n",
1188 p->id, p->type, p->name,
1189 p->minimum, p->maximum,
1190 p->step, p->default_value, p->flags);
1191 else
1192 dbgarg(cmd, "id=0x%x\n", p->id);
1193 break;
1194 }
1195 case VIDIOC_G_CTRL:
1196 {
1197 struct v4l2_control *p = arg;
1198
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001199 if (vfd->ctrl_handler)
1200 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1201 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001202 ret = ops->vidioc_g_ctrl(file, fh, p);
1203 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001204 struct v4l2_ext_controls ctrls;
1205 struct v4l2_ext_control ctrl;
1206
1207 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1208 ctrls.count = 1;
1209 ctrls.controls = &ctrl;
1210 ctrl.id = p->id;
1211 ctrl.value = p->value;
1212 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001213 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001214 if (ret == 0)
1215 p->value = ctrl.value;
1216 }
1217 } else
1218 break;
1219 if (!ret)
1220 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1221 else
1222 dbgarg(cmd, "id=0x%x\n", p->id);
1223 break;
1224 }
1225 case VIDIOC_S_CTRL:
1226 {
1227 struct v4l2_control *p = arg;
1228 struct v4l2_ext_controls ctrls;
1229 struct v4l2_ext_control ctrl;
1230
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001231 if (!vfd->ctrl_handler &&
1232 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001233 break;
1234
1235 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1236
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001237 if (vfd->ctrl_handler) {
1238 ret = v4l2_s_ctrl(vfd->ctrl_handler, p);
1239 break;
1240 }
Hans Verkuila3998102008-07-21 02:57:38 -03001241 if (ops->vidioc_s_ctrl) {
1242 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001243 break;
1244 }
Hans Verkuila3998102008-07-21 02:57:38 -03001245 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001246 break;
1247
1248 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1249 ctrls.count = 1;
1250 ctrls.controls = &ctrl;
1251 ctrl.id = p->id;
1252 ctrl.value = p->value;
1253 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001254 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001255 break;
1256 }
1257 case VIDIOC_G_EXT_CTRLS:
1258 {
1259 struct v4l2_ext_controls *p = arg;
1260
1261 p->error_idx = p->count;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001262 if (vfd->ctrl_handler)
1263 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1264 else if (ops->vidioc_g_ext_ctrls && check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001265 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001266 else
1267 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001268 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1269 break;
1270 }
1271 case VIDIOC_S_EXT_CTRLS:
1272 {
1273 struct v4l2_ext_controls *p = arg;
1274
1275 p->error_idx = p->count;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001276 if (!vfd->ctrl_handler && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001277 break;
1278 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001279 if (vfd->ctrl_handler)
1280 ret = v4l2_s_ext_ctrls(vfd->ctrl_handler, p);
1281 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001282 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001283 break;
1284 }
1285 case VIDIOC_TRY_EXT_CTRLS:
1286 {
1287 struct v4l2_ext_controls *p = arg;
1288
1289 p->error_idx = p->count;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001290 if (!vfd->ctrl_handler && !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001291 break;
1292 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001293 if (vfd->ctrl_handler)
1294 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1295 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001296 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001297 break;
1298 }
1299 case VIDIOC_QUERYMENU:
1300 {
1301 struct v4l2_querymenu *p = arg;
1302
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001303 if (vfd->ctrl_handler)
1304 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1305 else if (ops->vidioc_querymenu)
1306 ret = ops->vidioc_querymenu(file, fh, p);
1307 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001308 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001309 if (!ret)
1310 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1311 p->id, p->index, p->name);
1312 else
1313 dbgarg(cmd, "id=0x%x, index=%d\n",
1314 p->id, p->index);
1315 break;
1316 }
1317 /* --- audio ---------------------------------------------- */
1318 case VIDIOC_ENUMAUDIO:
1319 {
1320 struct v4l2_audio *p = arg;
1321
Hans Verkuila3998102008-07-21 02:57:38 -03001322 if (!ops->vidioc_enumaudio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001323 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001324 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001325 if (!ret)
1326 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1327 "mode=0x%x\n", p->index, p->name,
1328 p->capability, p->mode);
1329 else
1330 dbgarg(cmd, "index=%d\n", p->index);
1331 break;
1332 }
1333 case VIDIOC_G_AUDIO:
1334 {
1335 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001336
Hans Verkuila3998102008-07-21 02:57:38 -03001337 if (!ops->vidioc_g_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001338 break;
1339
Hans Verkuila3998102008-07-21 02:57:38 -03001340 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001341 if (!ret)
1342 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1343 "mode=0x%x\n", p->index,
1344 p->name, p->capability, p->mode);
1345 else
1346 dbgarg(cmd, "index=%d\n", p->index);
1347 break;
1348 }
1349 case VIDIOC_S_AUDIO:
1350 {
1351 struct v4l2_audio *p = arg;
1352
Hans Verkuila3998102008-07-21 02:57:38 -03001353 if (!ops->vidioc_s_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001354 break;
1355 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1356 "mode=0x%x\n", p->index, p->name,
1357 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001358 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001359 break;
1360 }
1361 case VIDIOC_ENUMAUDOUT:
1362 {
1363 struct v4l2_audioout *p = arg;
1364
Hans Verkuila3998102008-07-21 02:57:38 -03001365 if (!ops->vidioc_enumaudout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001366 break;
1367 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001368 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001369 if (!ret)
1370 dbgarg2("index=%d, name=%s, capability=%d, "
1371 "mode=%d\n", p->index, p->name,
1372 p->capability, p->mode);
1373 break;
1374 }
1375 case VIDIOC_G_AUDOUT:
1376 {
1377 struct v4l2_audioout *p = arg;
1378
Hans Verkuila3998102008-07-21 02:57:38 -03001379 if (!ops->vidioc_g_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001380 break;
Trent Piepho337f9d22009-03-04 01:21:02 -03001381
Hans Verkuila3998102008-07-21 02:57:38 -03001382 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001383 if (!ret)
1384 dbgarg2("index=%d, name=%s, capability=%d, "
1385 "mode=%d\n", p->index, p->name,
1386 p->capability, p->mode);
1387 break;
1388 }
1389 case VIDIOC_S_AUDOUT:
1390 {
1391 struct v4l2_audioout *p = arg;
1392
Hans Verkuila3998102008-07-21 02:57:38 -03001393 if (!ops->vidioc_s_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001394 break;
1395 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1396 "mode=%d\n", p->index, p->name,
1397 p->capability, p->mode);
1398
Hans Verkuila3998102008-07-21 02:57:38 -03001399 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001400 break;
1401 }
1402 case VIDIOC_G_MODULATOR:
1403 {
1404 struct v4l2_modulator *p = arg;
1405
Hans Verkuila3998102008-07-21 02:57:38 -03001406 if (!ops->vidioc_g_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001407 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001408 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001409 if (!ret)
1410 dbgarg(cmd, "index=%d, name=%s, "
1411 "capability=%d, rangelow=%d,"
1412 " rangehigh=%d, txsubchans=%d\n",
1413 p->index, p->name, p->capability,
1414 p->rangelow, p->rangehigh,
1415 p->txsubchans);
1416 break;
1417 }
1418 case VIDIOC_S_MODULATOR:
1419 {
1420 struct v4l2_modulator *p = arg;
1421
Hans Verkuila3998102008-07-21 02:57:38 -03001422 if (!ops->vidioc_s_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001423 break;
1424 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1425 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1426 p->index, p->name, p->capability, p->rangelow,
1427 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001428 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001429 break;
1430 }
1431 case VIDIOC_G_CROP:
1432 {
1433 struct v4l2_crop *p = arg;
1434
Hans Verkuila3998102008-07-21 02:57:38 -03001435 if (!ops->vidioc_g_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001436 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001437
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001438 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001439 ret = ops->vidioc_g_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001440 if (!ret)
1441 dbgrect(vfd, "", &p->c);
1442 break;
1443 }
1444 case VIDIOC_S_CROP:
1445 {
1446 struct v4l2_crop *p = arg;
1447
Hans Verkuila3998102008-07-21 02:57:38 -03001448 if (!ops->vidioc_s_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001449 break;
1450 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1451 dbgrect(vfd, "", &p->c);
Hans Verkuila3998102008-07-21 02:57:38 -03001452 ret = ops->vidioc_s_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001453 break;
1454 }
1455 case VIDIOC_CROPCAP:
1456 {
1457 struct v4l2_cropcap *p = arg;
1458
1459 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuila3998102008-07-21 02:57:38 -03001460 if (!ops->vidioc_cropcap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001461 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001462
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001463 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001464 ret = ops->vidioc_cropcap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001465 if (!ret) {
1466 dbgrect(vfd, "bounds ", &p->bounds);
1467 dbgrect(vfd, "defrect ", &p->defrect);
1468 }
1469 break;
1470 }
1471 case VIDIOC_G_JPEGCOMP:
1472 {
1473 struct v4l2_jpegcompression *p = arg;
1474
Hans Verkuila3998102008-07-21 02:57:38 -03001475 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001476 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001477
Hans Verkuila3998102008-07-21 02:57:38 -03001478 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001479 if (!ret)
1480 dbgarg(cmd, "quality=%d, APPn=%d, "
1481 "APP_len=%d, COM_len=%d, "
1482 "jpeg_markers=%d\n",
1483 p->quality, p->APPn, p->APP_len,
1484 p->COM_len, p->jpeg_markers);
1485 break;
1486 }
1487 case VIDIOC_S_JPEGCOMP:
1488 {
1489 struct v4l2_jpegcompression *p = arg;
1490
Hans Verkuila3998102008-07-21 02:57:38 -03001491 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001492 break;
1493 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1494 "COM_len=%d, jpeg_markers=%d\n",
1495 p->quality, p->APPn, p->APP_len,
1496 p->COM_len, p->jpeg_markers);
Hans Verkuila3998102008-07-21 02:57:38 -03001497 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001498 break;
1499 }
1500 case VIDIOC_G_ENC_INDEX:
1501 {
1502 struct v4l2_enc_idx *p = arg;
1503
Hans Verkuila3998102008-07-21 02:57:38 -03001504 if (!ops->vidioc_g_enc_index)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001505 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001506 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001507 if (!ret)
1508 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1509 p->entries, p->entries_cap);
1510 break;
1511 }
1512 case VIDIOC_ENCODER_CMD:
1513 {
1514 struct v4l2_encoder_cmd *p = arg;
1515
Hans Verkuila3998102008-07-21 02:57:38 -03001516 if (!ops->vidioc_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001517 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001518 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001519 if (!ret)
1520 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1521 break;
1522 }
1523 case VIDIOC_TRY_ENCODER_CMD:
1524 {
1525 struct v4l2_encoder_cmd *p = arg;
1526
Hans Verkuila3998102008-07-21 02:57:38 -03001527 if (!ops->vidioc_try_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001528 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001529 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001530 if (!ret)
1531 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1532 break;
1533 }
1534 case VIDIOC_G_PARM:
1535 {
1536 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001537
Hans Verkuila3998102008-07-21 02:57:38 -03001538 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001539 ret = check_fmt(ops, p->type);
1540 if (ret)
1541 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001542 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001543 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001544 v4l2_std_id std = vfd->current_norm;
1545
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001546 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001547 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001548
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001549 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001550 if (ops->vidioc_g_std)
1551 ret = ops->vidioc_g_std(file, fh, &std);
1552 else if (std == 0)
1553 ret = -EINVAL;
1554 if (ret == 0)
1555 v4l2_video_std_frame_period(std,
1556 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001557 }
1558
1559 dbgarg(cmd, "type=%d\n", p->type);
1560 break;
1561 }
1562 case VIDIOC_S_PARM:
1563 {
1564 struct v4l2_streamparm *p = arg;
1565
Hans Verkuila3998102008-07-21 02:57:38 -03001566 if (!ops->vidioc_s_parm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001567 break;
Trent Piepho34796bc2009-03-28 22:25:35 -03001568 ret = check_fmt(ops, p->type);
1569 if (ret)
1570 break;
1571
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001572 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001573 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001574 break;
1575 }
1576 case VIDIOC_G_TUNER:
1577 {
1578 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001579
Hans Verkuila3998102008-07-21 02:57:38 -03001580 if (!ops->vidioc_g_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001581 break;
1582
Hans Verkuila3998102008-07-21 02:57:38 -03001583 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001584 if (!ret)
1585 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1586 "capability=0x%x, rangelow=%d, "
1587 "rangehigh=%d, signal=%d, afc=%d, "
1588 "rxsubchans=0x%x, audmode=%d\n",
1589 p->index, p->name, p->type,
1590 p->capability, p->rangelow,
1591 p->rangehigh, p->signal, p->afc,
1592 p->rxsubchans, p->audmode);
1593 break;
1594 }
1595 case VIDIOC_S_TUNER:
1596 {
1597 struct v4l2_tuner *p = arg;
1598
Hans Verkuila3998102008-07-21 02:57:38 -03001599 if (!ops->vidioc_s_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001600 break;
1601 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1602 "capability=0x%x, rangelow=%d, "
1603 "rangehigh=%d, signal=%d, afc=%d, "
1604 "rxsubchans=0x%x, audmode=%d\n",
1605 p->index, p->name, p->type,
1606 p->capability, p->rangelow,
1607 p->rangehigh, p->signal, p->afc,
1608 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001609 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001610 break;
1611 }
1612 case VIDIOC_G_FREQUENCY:
1613 {
1614 struct v4l2_frequency *p = arg;
1615
Hans Verkuila3998102008-07-21 02:57:38 -03001616 if (!ops->vidioc_g_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001617 break;
1618
Hans Verkuila3998102008-07-21 02:57:38 -03001619 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001620 if (!ret)
1621 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1622 p->tuner, p->type, p->frequency);
1623 break;
1624 }
1625 case VIDIOC_S_FREQUENCY:
1626 {
1627 struct v4l2_frequency *p = arg;
1628
Hans Verkuila3998102008-07-21 02:57:38 -03001629 if (!ops->vidioc_s_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001630 break;
1631 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1632 p->tuner, p->type, p->frequency);
Hans Verkuila3998102008-07-21 02:57:38 -03001633 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001634 break;
1635 }
1636 case VIDIOC_G_SLICED_VBI_CAP:
1637 {
1638 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001639
Hans Verkuila3998102008-07-21 02:57:38 -03001640 if (!ops->vidioc_g_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001641 break;
Trent Piepho19c96e42009-03-04 01:21:02 -03001642
1643 /* Clear up to type, everything after type is zerod already */
1644 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1645
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001646 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001647 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001648 if (!ret)
1649 dbgarg2("service_set=%d\n", p->service_set);
1650 break;
1651 }
1652 case VIDIOC_LOG_STATUS:
1653 {
Hans Verkuila3998102008-07-21 02:57:38 -03001654 if (!ops->vidioc_log_status)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001655 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001656 ret = ops->vidioc_log_status(file, fh);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001657 break;
1658 }
1659#ifdef CONFIG_VIDEO_ADV_DEBUG
1660 case VIDIOC_DBG_G_REGISTER:
1661 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001662 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001663
Hans Verkuila1198cc2011-01-08 09:53:32 -03001664 if (ops->vidioc_g_register) {
1665 if (!capable(CAP_SYS_ADMIN))
1666 ret = -EPERM;
1667 else
1668 ret = ops->vidioc_g_register(file, fh, p);
1669 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001670 break;
1671 }
1672 case VIDIOC_DBG_S_REGISTER:
1673 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001674 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001675
Hans Verkuila1198cc2011-01-08 09:53:32 -03001676 if (ops->vidioc_s_register) {
1677 if (!capable(CAP_SYS_ADMIN))
1678 ret = -EPERM;
1679 else
1680 ret = ops->vidioc_s_register(file, fh, p);
1681 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001682 break;
1683 }
1684#endif
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001685 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001686 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001687 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001688
Hans Verkuila3998102008-07-21 02:57:38 -03001689 if (!ops->vidioc_g_chip_ident)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001690 break;
Hans Verkuil80b36e02009-02-07 11:00:02 -03001691 p->ident = V4L2_IDENT_NONE;
1692 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001693 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001694 if (!ret)
1695 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1696 break;
1697 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001698 case VIDIOC_S_HW_FREQ_SEEK:
1699 {
1700 struct v4l2_hw_freq_seek *p = arg;
1701
Hans Verkuila3998102008-07-21 02:57:38 -03001702 if (!ops->vidioc_s_hw_freq_seek)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001703 break;
1704 dbgarg(cmd,
1705 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1706 p->tuner, p->type, p->seek_upward, p->wrap_around);
Hans Verkuila3998102008-07-21 02:57:38 -03001707 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1708 break;
1709 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001710 case VIDIOC_ENUM_FRAMESIZES:
1711 {
1712 struct v4l2_frmsizeenum *p = arg;
1713
1714 if (!ops->vidioc_enum_framesizes)
1715 break;
1716
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001717 ret = ops->vidioc_enum_framesizes(file, fh, p);
1718 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001719 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1720 p->index,
1721 (p->pixel_format & 0xff),
1722 (p->pixel_format >> 8) & 0xff,
1723 (p->pixel_format >> 16) & 0xff,
1724 (p->pixel_format >> 24) & 0xff,
1725 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001726 switch (p->type) {
1727 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001728 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001729 p->discrete.width, p->discrete.height);
1730 break;
1731 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001732 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001733 p->stepwise.min_width, p->stepwise.min_height,
1734 p->stepwise.step_width, p->stepwise.step_height,
1735 p->stepwise.max_width, p->stepwise.max_height);
1736 break;
1737 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001738 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001739 break;
1740 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001741 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001742 }
1743
1744 break;
1745 }
1746 case VIDIOC_ENUM_FRAMEINTERVALS:
1747 {
1748 struct v4l2_frmivalenum *p = arg;
1749
1750 if (!ops->vidioc_enum_frameintervals)
1751 break;
1752
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001753 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1754 dbgarg(cmd,
1755 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1756 p->index, p->pixel_format,
1757 p->width, p->height, p->type);
1758 switch (p->type) {
1759 case V4L2_FRMIVAL_TYPE_DISCRETE:
1760 dbgarg2("fps=%d/%d\n",
1761 p->discrete.numerator,
1762 p->discrete.denominator);
1763 break;
1764 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001765 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1766 p->stepwise.min.numerator,
1767 p->stepwise.min.denominator,
1768 p->stepwise.max.numerator,
1769 p->stepwise.max.denominator,
1770 p->stepwise.step.numerator,
1771 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001772 break;
1773 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1774 dbgarg2("continuous\n");
1775 break;
1776 default:
1777 dbgarg2("- Unknown type!\n");
1778 }
1779 break;
1780 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001781 case VIDIOC_ENUM_DV_PRESETS:
1782 {
1783 struct v4l2_dv_enum_preset *p = arg;
1784
1785 if (!ops->vidioc_enum_dv_presets)
1786 break;
1787
1788 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1789 if (!ret)
1790 dbgarg(cmd,
1791 "index=%d, preset=%d, name=%s, width=%d,"
1792 " height=%d ",
1793 p->index, p->preset, p->name, p->width,
1794 p->height);
1795 break;
1796 }
1797 case VIDIOC_S_DV_PRESET:
1798 {
1799 struct v4l2_dv_preset *p = arg;
1800
1801 if (!ops->vidioc_s_dv_preset)
1802 break;
1803
1804 dbgarg(cmd, "preset=%d\n", p->preset);
1805 ret = ops->vidioc_s_dv_preset(file, fh, p);
1806 break;
1807 }
1808 case VIDIOC_G_DV_PRESET:
1809 {
1810 struct v4l2_dv_preset *p = arg;
1811
1812 if (!ops->vidioc_g_dv_preset)
1813 break;
1814
1815 ret = ops->vidioc_g_dv_preset(file, fh, p);
1816 if (!ret)
1817 dbgarg(cmd, "preset=%d\n", p->preset);
1818 break;
1819 }
1820 case VIDIOC_QUERY_DV_PRESET:
1821 {
1822 struct v4l2_dv_preset *p = arg;
1823
1824 if (!ops->vidioc_query_dv_preset)
1825 break;
1826
1827 ret = ops->vidioc_query_dv_preset(file, fh, p);
1828 if (!ret)
1829 dbgarg(cmd, "preset=%d\n", p->preset);
1830 break;
1831 }
1832 case VIDIOC_S_DV_TIMINGS:
1833 {
1834 struct v4l2_dv_timings *p = arg;
1835
1836 if (!ops->vidioc_s_dv_timings)
1837 break;
1838
1839 switch (p->type) {
1840 case V4L2_DV_BT_656_1120:
1841 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
1842 " width=%d, height=%d, polarities=%x,"
1843 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
1844 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
1845 " il_vfrontporch=%d, il_vsync=%d,"
1846 " il_vbackporch=%d\n",
1847 p->bt.interlaced, p->bt.pixelclock,
1848 p->bt.width, p->bt.height, p->bt.polarities,
1849 p->bt.hfrontporch, p->bt.hsync,
1850 p->bt.hbackporch, p->bt.vfrontporch,
1851 p->bt.vsync, p->bt.vbackporch,
1852 p->bt.il_vfrontporch, p->bt.il_vsync,
1853 p->bt.il_vbackporch);
1854 ret = ops->vidioc_s_dv_timings(file, fh, p);
1855 break;
1856 default:
1857 dbgarg2("Unknown type %d!\n", p->type);
1858 break;
1859 }
1860 break;
1861 }
1862 case VIDIOC_G_DV_TIMINGS:
1863 {
1864 struct v4l2_dv_timings *p = arg;
1865
1866 if (!ops->vidioc_g_dv_timings)
1867 break;
1868
1869 ret = ops->vidioc_g_dv_timings(file, fh, p);
1870 if (!ret) {
1871 switch (p->type) {
1872 case V4L2_DV_BT_656_1120:
1873 dbgarg2("bt-656/1120:interlaced=%d,"
1874 " pixelclock=%lld,"
1875 " width=%d, height=%d, polarities=%x,"
1876 " hfrontporch=%d, hsync=%d,"
1877 " hbackporch=%d, vfrontporch=%d,"
1878 " vsync=%d, vbackporch=%d,"
1879 " il_vfrontporch=%d, il_vsync=%d,"
1880 " il_vbackporch=%d\n",
1881 p->bt.interlaced, p->bt.pixelclock,
1882 p->bt.width, p->bt.height,
1883 p->bt.polarities, p->bt.hfrontporch,
1884 p->bt.hsync, p->bt.hbackporch,
1885 p->bt.vfrontporch, p->bt.vsync,
1886 p->bt.vbackporch, p->bt.il_vfrontporch,
1887 p->bt.il_vsync, p->bt.il_vbackporch);
1888 break;
1889 default:
1890 dbgarg2("Unknown type %d!\n", p->type);
1891 break;
1892 }
1893 }
1894 break;
1895 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03001896 case VIDIOC_DQEVENT:
1897 {
1898 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001899
Sakari Ailusd3d7c962010-03-27 11:02:10 -03001900 if (!ops->vidioc_subscribe_event)
1901 break;
1902
1903 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
1904 if (ret < 0) {
1905 dbgarg(cmd, "no pending events?");
1906 break;
1907 }
1908 dbgarg(cmd,
1909 "pending=%d, type=0x%8.8x, sequence=%d, "
1910 "timestamp=%lu.%9.9lu ",
1911 ev->pending, ev->type, ev->sequence,
1912 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
1913 break;
1914 }
1915 case VIDIOC_SUBSCRIBE_EVENT:
1916 {
1917 struct v4l2_event_subscription *sub = arg;
1918
1919 if (!ops->vidioc_subscribe_event)
1920 break;
1921
1922 ret = ops->vidioc_subscribe_event(fh, sub);
1923 if (ret < 0) {
1924 dbgarg(cmd, "failed, ret=%ld", ret);
1925 break;
1926 }
1927 dbgarg(cmd, "type=0x%8.8x", sub->type);
1928 break;
1929 }
1930 case VIDIOC_UNSUBSCRIBE_EVENT:
1931 {
1932 struct v4l2_event_subscription *sub = arg;
1933
1934 if (!ops->vidioc_unsubscribe_event)
1935 break;
1936
1937 ret = ops->vidioc_unsubscribe_event(fh, sub);
1938 if (ret < 0) {
1939 dbgarg(cmd, "failed, ret=%ld", ret);
1940 break;
1941 }
1942 dbgarg(cmd, "type=0x%8.8x", sub->type);
1943 break;
1944 }
Hans Verkuila3998102008-07-21 02:57:38 -03001945 default:
1946 {
1947 if (!ops->vidioc_default)
1948 break;
1949 ret = ops->vidioc_default(file, fh, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001950 break;
1951 }
1952 } /* switch */
1953
1954 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1955 if (ret < 0) {
1956 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03001957 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001958 }
1959 }
1960
1961 return ret;
1962}
1963
Trent Piepho19c96e42009-03-04 01:21:02 -03001964/* In some cases, only a few fields are used as input, i.e. when the app sets
1965 * "index" and then the driver fills in the rest of the structure for the thing
1966 * with that index. We only need to copy up the first non-input field. */
1967static unsigned long cmd_input_size(unsigned int cmd)
1968{
1969 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03001970#define CMDINSIZE(cmd, type, field) \
1971 case VIDIOC_##cmd: \
1972 return offsetof(struct v4l2_##type, field) + \
1973 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03001974
Hans Verkuil9f1a6932009-03-08 10:35:23 -03001975 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03001976 CMDINSIZE(ENUM_FMT, fmtdesc, type);
1977 CMDINSIZE(G_FMT, format, type);
1978 CMDINSIZE(QUERYBUF, buffer, type);
1979 CMDINSIZE(G_PARM, streamparm, type);
1980 CMDINSIZE(ENUMSTD, standard, index);
1981 CMDINSIZE(ENUMINPUT, input, index);
1982 CMDINSIZE(G_CTRL, control, id);
1983 CMDINSIZE(G_TUNER, tuner, index);
1984 CMDINSIZE(QUERYCTRL, queryctrl, id);
1985 CMDINSIZE(QUERYMENU, querymenu, index);
1986 CMDINSIZE(ENUMOUTPUT, output, index);
1987 CMDINSIZE(G_MODULATOR, modulator, index);
1988 CMDINSIZE(G_FREQUENCY, frequency, tuner);
1989 CMDINSIZE(CROPCAP, cropcap, type);
1990 CMDINSIZE(G_CROP, crop, type);
1991 CMDINSIZE(ENUMAUDIO, audio, index);
1992 CMDINSIZE(ENUMAUDOUT, audioout, index);
1993 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
1994 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
1995 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
1996 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
1997 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
1998 default:
1999 return _IOC_SIZE(cmd);
2000 }
2001}
2002
Hans Verkuil069b7472008-12-30 07:04:34 -03002003long video_ioctl2(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002004 unsigned int cmd, unsigned long arg)
2005{
2006 char sbuf[128];
2007 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002008 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002009 long err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002010 int is_ext_ctrl;
2011 size_t ctrls_size = 0;
2012 void __user *user_ptr = NULL;
2013
2014#ifdef __OLD_VIDIOC_
2015 cmd = video_fix_command(cmd);
2016#endif
2017 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
2018 cmd == VIDIOC_TRY_EXT_CTRLS);
2019
2020 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002021 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002022 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2023 parg = sbuf;
2024 } else {
2025 /* too big to allocate from stack */
2026 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2027 if (NULL == mbuf)
2028 return -ENOMEM;
2029 parg = mbuf;
2030 }
2031
2032 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002033 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2034 unsigned long n = cmd_input_size(cmd);
2035
2036 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002037 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002038
2039 /* zero out anything we don't copy from userspace */
2040 if (n < _IOC_SIZE(cmd))
2041 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002042 } else {
2043 /* read-only ioctl */
2044 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002045 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002046 }
2047
2048 if (is_ext_ctrl) {
2049 struct v4l2_ext_controls *p = parg;
2050
2051 /* In case of an error, tell the caller that it wasn't
2052 a specific control that caused it. */
2053 p->error_idx = p->count;
2054 user_ptr = (void __user *)p->controls;
2055 if (p->count) {
2056 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
2057 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
2058 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
2059 err = -ENOMEM;
2060 if (NULL == mbuf)
2061 goto out_ext_ctrl;
2062 err = -EFAULT;
2063 if (copy_from_user(mbuf, user_ptr, ctrls_size))
2064 goto out_ext_ctrl;
2065 p->controls = mbuf;
2066 }
2067 }
2068
2069 /* Handles IOCTL */
Mauro Carvalho Chehabb1f88402008-10-21 11:27:20 -03002070 err = __video_do_ioctl(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002071 if (err == -ENOIOCTLCMD)
2072 err = -EINVAL;
2073 if (is_ext_ctrl) {
2074 struct v4l2_ext_controls *p = parg;
2075
2076 p->controls = (void *)user_ptr;
2077 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
2078 err = -EFAULT;
2079 goto out_ext_ctrl;
2080 }
2081 if (err < 0)
2082 goto out;
2083
2084out_ext_ctrl:
2085 /* Copy results into user buffer */
2086 switch (_IOC_DIR(cmd)) {
2087 case _IOC_READ:
2088 case (_IOC_WRITE | _IOC_READ):
2089 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2090 err = -EFAULT;
2091 break;
2092 }
2093
2094out:
2095 kfree(mbuf);
2096 return err;
2097}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002098EXPORT_SYMBOL(video_ioctl2);