blob: 0eeceae503293da68debf793fb40e10906f17acb [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 */
Mauro Carvalho Chehab7e0a16f2009-03-10 05:31:34 -030021#include <linux/videodev.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030022#include <linux/videodev2.h>
23
24#ifdef CONFIG_VIDEO_V4L1
25#include <linux/videodev.h>
26#endif
27#include <media/v4l2-common.h>
28#include <media/v4l2-ioctl.h>
Sakari Ailusd3d7c962010-03-27 11:02:10 -030029#include <media/v4l2-fh.h>
30#include <media/v4l2-event.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030031#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030032
33#define dbgarg(cmd, fmt, arg...) \
34 do { \
35 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
36 printk(KERN_DEBUG "%s: ", vfd->name); \
37 v4l_printk_ioctl(cmd); \
38 printk(" " fmt, ## arg); \
39 } \
40 } while (0)
41
42#define dbgarg2(fmt, arg...) \
43 do { \
44 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
45 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
46 } while (0)
47
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030048#define dbgarg3(fmt, arg...) \
49 do { \
50 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
51 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
52 } while (0)
53
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030054/* Zero out the end of the struct pointed to by p. Everthing after, but
55 * not including, the specified field is cleared. */
56#define CLEAR_AFTER_FIELD(p, field) \
57 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
58 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
59
Hans Verkuil35ea11f2008-07-20 08:12:02 -030060struct std_descr {
61 v4l2_std_id std;
62 const char *descr;
63};
64
65static const struct std_descr standards[] = {
66 { V4L2_STD_NTSC, "NTSC" },
67 { V4L2_STD_NTSC_M, "NTSC-M" },
68 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
69 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
70 { V4L2_STD_NTSC_443, "NTSC-443" },
71 { V4L2_STD_PAL, "PAL" },
72 { V4L2_STD_PAL_BG, "PAL-BG" },
73 { V4L2_STD_PAL_B, "PAL-B" },
74 { V4L2_STD_PAL_B1, "PAL-B1" },
75 { V4L2_STD_PAL_G, "PAL-G" },
76 { V4L2_STD_PAL_H, "PAL-H" },
77 { V4L2_STD_PAL_I, "PAL-I" },
78 { V4L2_STD_PAL_DK, "PAL-DK" },
79 { V4L2_STD_PAL_D, "PAL-D" },
80 { V4L2_STD_PAL_D1, "PAL-D1" },
81 { V4L2_STD_PAL_K, "PAL-K" },
82 { V4L2_STD_PAL_M, "PAL-M" },
83 { V4L2_STD_PAL_N, "PAL-N" },
84 { V4L2_STD_PAL_Nc, "PAL-Nc" },
85 { V4L2_STD_PAL_60, "PAL-60" },
86 { V4L2_STD_SECAM, "SECAM" },
87 { V4L2_STD_SECAM_B, "SECAM-B" },
88 { V4L2_STD_SECAM_G, "SECAM-G" },
89 { V4L2_STD_SECAM_H, "SECAM-H" },
90 { V4L2_STD_SECAM_DK, "SECAM-DK" },
91 { V4L2_STD_SECAM_D, "SECAM-D" },
92 { V4L2_STD_SECAM_K, "SECAM-K" },
93 { V4L2_STD_SECAM_K1, "SECAM-K1" },
94 { V4L2_STD_SECAM_L, "SECAM-L" },
95 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
96 { 0, "Unknown" }
97};
98
99/* video4linux standard ID conversion to standard name
100 */
101const char *v4l2_norm_to_name(v4l2_std_id id)
102{
103 u32 myid = id;
104 int i;
105
106 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
107 64 bit comparations. So, on that architecture, with some gcc
108 variants, compilation fails. Currently, the max value is 30bit wide.
109 */
110 BUG_ON(myid != id);
111
112 for (i = 0; standards[i].std; i++)
113 if (myid == standards[i].std)
114 break;
115 return standards[i].descr;
116}
117EXPORT_SYMBOL(v4l2_norm_to_name);
118
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300119/* Returns frame period for the given standard */
120void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
121{
122 if (id & V4L2_STD_525_60) {
123 frameperiod->numerator = 1001;
124 frameperiod->denominator = 30000;
125 } else {
126 frameperiod->numerator = 1;
127 frameperiod->denominator = 25;
128 }
129}
130EXPORT_SYMBOL(v4l2_video_std_frame_period);
131
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300132/* Fill in the fields of a v4l2_standard structure according to the
133 'id' and 'transmission' parameters. Returns negative on error. */
134int v4l2_video_std_construct(struct v4l2_standard *vs,
135 int id, const char *name)
136{
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300137 vs->id = id;
138 v4l2_video_std_frame_period(id, &vs->frameperiod);
139 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300140 strlcpy(vs->name, name, sizeof(vs->name));
141 return 0;
142}
143EXPORT_SYMBOL(v4l2_video_std_construct);
144
145/* ----------------------------------------------------------------- */
146/* some arrays for pretty-printing debug messages of enum types */
147
148const char *v4l2_field_names[] = {
149 [V4L2_FIELD_ANY] = "any",
150 [V4L2_FIELD_NONE] = "none",
151 [V4L2_FIELD_TOP] = "top",
152 [V4L2_FIELD_BOTTOM] = "bottom",
153 [V4L2_FIELD_INTERLACED] = "interlaced",
154 [V4L2_FIELD_SEQ_TB] = "seq-tb",
155 [V4L2_FIELD_SEQ_BT] = "seq-bt",
156 [V4L2_FIELD_ALTERNATE] = "alternate",
157 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
158 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
159};
160EXPORT_SYMBOL(v4l2_field_names);
161
162const char *v4l2_type_names[] = {
163 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
164 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
165 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
166 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
167 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
168 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
169 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
170 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
171};
172EXPORT_SYMBOL(v4l2_type_names);
173
174static const char *v4l2_memory_names[] = {
175 [V4L2_MEMORY_MMAP] = "mmap",
176 [V4L2_MEMORY_USERPTR] = "userptr",
177 [V4L2_MEMORY_OVERLAY] = "overlay",
178};
179
180#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
181 arr[a] : "unknown")
182
183/* ------------------------------------------------------------------ */
184/* debug help functions */
185
186#ifdef CONFIG_VIDEO_V4L1_COMPAT
187static const char *v4l1_ioctls[] = {
188 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
189 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
190 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
191 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
192 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
193 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
194 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
195 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
196 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
197 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
198 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
199 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
200 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
201 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
202 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
203 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
204 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
205 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
206 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
207 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
208 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
209 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
210 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
211 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
212 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
213 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
214 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
215 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
216 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
217};
218#define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
219#endif
220
221static const char *v4l2_ioctls[] = {
222 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
223 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
224 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
225 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
226 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
227 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
228 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
229 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
230 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
231 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
232 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
233 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
234 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
235 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
236 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
237 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
238 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
239 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
240 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
241 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
242 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
243 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
244 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
245 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
246 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
247 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
248 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
249 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
250 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
251 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
252 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
253 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
254 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
255 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
256 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
257 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
258 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
259 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
260 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
261 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
262 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
263 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
264 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
265 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
266 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
267 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
268 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
269 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
270 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
271 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
272 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
273 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
274 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
275 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
276 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
277#if 1
278 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
279 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
280 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
281 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
282 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
283
284 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
285 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
286
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300287 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300288 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
289#endif
Muralidharan Karicherib6456c02009-11-19 12:00:31 -0300290 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS",
291 [_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET",
292 [_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET",
293 [_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET",
294 [_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS",
295 [_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS",
Sakari Ailusfda10212010-02-24 19:19:05 -0300296 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
297 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
298 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300299};
300#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
301
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300302/* Common ioctl debug function. This function can be used by
303 external ioctl messages as well as internal V4L ioctl */
304void v4l_printk_ioctl(unsigned int cmd)
305{
306 char *dir, *type;
307
308 switch (_IOC_TYPE(cmd)) {
309 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300310 type = "v4l2_int";
311 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300312#ifdef CONFIG_VIDEO_V4L1_COMPAT
313 case 'v':
314 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
315 type = "v4l1";
316 break;
317 }
318 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
319 return;
320#endif
321 case 'V':
322 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
323 type = "v4l2";
324 break;
325 }
326 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
327 return;
328 default:
329 type = "unknown";
330 }
331
332 switch (_IOC_DIR(cmd)) {
333 case _IOC_NONE: dir = "--"; break;
334 case _IOC_READ: dir = "r-"; break;
335 case _IOC_WRITE: dir = "-w"; break;
336 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
337 default: dir = "*ERR*"; break;
338 }
339 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
340 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
341}
342EXPORT_SYMBOL(v4l_printk_ioctl);
343
344/*
345 * helper function -- handles userspace copying for ioctl arguments
346 */
347
348#ifdef __OLD_VIDIOC_
349static unsigned int
350video_fix_command(unsigned int cmd)
351{
352 switch (cmd) {
353 case VIDIOC_OVERLAY_OLD:
354 cmd = VIDIOC_OVERLAY;
355 break;
356 case VIDIOC_S_PARM_OLD:
357 cmd = VIDIOC_S_PARM;
358 break;
359 case VIDIOC_S_CTRL_OLD:
360 cmd = VIDIOC_S_CTRL;
361 break;
362 case VIDIOC_G_AUDIO_OLD:
363 cmd = VIDIOC_G_AUDIO;
364 break;
365 case VIDIOC_G_AUDOUT_OLD:
366 cmd = VIDIOC_G_AUDOUT;
367 break;
368 case VIDIOC_CROPCAP_OLD:
369 cmd = VIDIOC_CROPCAP;
370 break;
371 }
372 return cmd;
373}
374#endif
375
376/*
377 * Obsolete usercopy function - Should be removed soon
378 */
Hans Verkuil069b7472008-12-30 07:04:34 -0300379long
Hans Verkuilf473bf72008-11-01 08:25:11 -0300380video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
381 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300382{
383 char sbuf[128];
384 void *mbuf = NULL;
385 void *parg = NULL;
Hans Verkuil069b7472008-12-30 07:04:34 -0300386 long err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300387 int is_ext_ctrl;
388 size_t ctrls_size = 0;
389 void __user *user_ptr = NULL;
390
391#ifdef __OLD_VIDIOC_
392 cmd = video_fix_command(cmd);
393#endif
394 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
395 cmd == VIDIOC_TRY_EXT_CTRLS);
396
397 /* Copy arguments into temp kernel buffer */
398 switch (_IOC_DIR(cmd)) {
399 case _IOC_NONE:
400 parg = NULL;
401 break;
402 case _IOC_READ:
403 case _IOC_WRITE:
404 case (_IOC_WRITE | _IOC_READ):
405 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
406 parg = sbuf;
407 } else {
408 /* too big to allocate from stack */
409 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
410 if (NULL == mbuf)
411 return -ENOMEM;
412 parg = mbuf;
413 }
414
415 err = -EFAULT;
416 if (_IOC_DIR(cmd) & _IOC_WRITE)
417 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
418 goto out;
419 break;
420 }
421 if (is_ext_ctrl) {
422 struct v4l2_ext_controls *p = parg;
423
424 /* In case of an error, tell the caller that it wasn't
425 a specific control that caused it. */
426 p->error_idx = p->count;
427 user_ptr = (void __user *)p->controls;
428 if (p->count) {
429 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
430 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
431 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
432 err = -ENOMEM;
433 if (NULL == mbuf)
434 goto out_ext_ctrl;
435 err = -EFAULT;
436 if (copy_from_user(mbuf, user_ptr, ctrls_size))
437 goto out_ext_ctrl;
438 p->controls = mbuf;
439 }
440 }
441
442 /* call driver */
Hans Verkuilf473bf72008-11-01 08:25:11 -0300443 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300444 if (err == -ENOIOCTLCMD)
445 err = -EINVAL;
446 if (is_ext_ctrl) {
447 struct v4l2_ext_controls *p = parg;
448
449 p->controls = (void *)user_ptr;
450 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
451 err = -EFAULT;
452 goto out_ext_ctrl;
453 }
454 if (err < 0)
455 goto out;
456
457out_ext_ctrl:
458 /* Copy results into user buffer */
459 switch (_IOC_DIR(cmd)) {
460 case _IOC_READ:
461 case (_IOC_WRITE | _IOC_READ):
462 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
463 err = -EFAULT;
464 break;
465 }
466
467out:
468 kfree(mbuf);
469 return err;
470}
471EXPORT_SYMBOL(video_usercopy);
472
473static void dbgbuf(unsigned int cmd, struct video_device *vfd,
474 struct v4l2_buffer *p)
475{
476 struct v4l2_timecode *tc = &p->timecode;
477
478 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
479 "bytesused=%d, flags=0x%08d, "
480 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
481 p->timestamp.tv_sec / 3600,
482 (int)(p->timestamp.tv_sec / 60) % 60,
483 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300484 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300485 p->index,
486 prt_names(p->type, v4l2_type_names),
487 p->bytesused, p->flags,
488 p->field, p->sequence,
489 prt_names(p->memory, v4l2_memory_names),
490 p->m.userptr, p->length);
491 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
492 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
493 tc->hours, tc->minutes, tc->seconds,
494 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
495}
496
497static inline void dbgrect(struct video_device *vfd, char *s,
498 struct v4l2_rect *r)
499{
500 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
501 r->width, r->height);
502};
503
504static inline void v4l_print_pix_fmt(struct video_device *vfd,
505 struct v4l2_pix_format *fmt)
506{
507 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
508 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
509 fmt->width, fmt->height,
510 (fmt->pixelformat & 0xff),
511 (fmt->pixelformat >> 8) & 0xff,
512 (fmt->pixelformat >> 16) & 0xff,
513 (fmt->pixelformat >> 24) & 0xff,
514 prt_names(fmt->field, v4l2_field_names),
515 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
516};
517
518static inline void v4l_print_ext_ctrls(unsigned int cmd,
519 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
520{
521 __u32 i;
522
523 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
524 return;
525 dbgarg(cmd, "");
526 printk(KERN_CONT "class=0x%x", c->ctrl_class);
527 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300528 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300529 printk(KERN_CONT " id/val=0x%x/0x%x",
530 c->controls[i].id, c->controls[i].value);
531 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300532 printk(KERN_CONT " id=0x%x,size=%u",
533 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300534 }
535 printk(KERN_CONT "\n");
536};
537
538static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
539{
540 __u32 i;
541
542 /* zero the reserved fields */
543 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300544 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300545 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300546
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300547 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
548 when using extended controls.
549 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
550 is it allowed for backwards compatibility.
551 */
552 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
553 return 0;
554 /* Check that all controls are from the same control class. */
555 for (i = 0; i < c->count; i++) {
556 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
557 c->error_idx = i;
558 return 0;
559 }
560 }
561 return 1;
562}
563
Hans Verkuila3998102008-07-21 02:57:38 -0300564static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300565{
Hans Verkuila3998102008-07-21 02:57:38 -0300566 if (ops == NULL)
567 return -EINVAL;
568
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300569 switch (type) {
570 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300571 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300572 return 0;
573 break;
574 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300575 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300576 return 0;
577 break;
578 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300579 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300580 return 0;
581 break;
582 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300583 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300584 return 0;
585 break;
586 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300587 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300588 return 0;
589 break;
590 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300591 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300592 return 0;
593 break;
594 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300595 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300596 return 0;
597 break;
598 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300599 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300600 return 0;
601 break;
602 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300603 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300604 return 0;
605 break;
606 }
607 return -EINVAL;
608}
609
Hans Verkuil069b7472008-12-30 07:04:34 -0300610static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300611 unsigned int cmd, void *arg)
612{
613 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300614 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300615 void *fh = file->private_data;
Hans Verkuil069b7472008-12-30 07:04:34 -0300616 long ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300617
Hans Verkuil6a717882010-04-06 15:56:08 -0300618 if (ops == NULL) {
619 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
620 vfd->name);
621 return -EINVAL;
622 }
623
624#ifdef CONFIG_VIDEO_V4L1_COMPAT
625 /********************************************************
626 All other V4L1 calls are handled by v4l1_compat module.
627 Those calls will be translated into V4L2 calls, and
628 __video_do_ioctl will be called again, with one or more
629 V4L2 ioctls.
630 ********************************************************/
631 if (_IOC_TYPE(cmd) == 'v' && cmd != VIDIOCGMBUF &&
632 _IOC_NR(cmd) < BASE_VIDIOCPRIVATE) {
633 return v4l_compat_translate_ioctl(file, cmd, arg,
634 __video_do_ioctl);
635 }
636#endif
637
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300638 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
639 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
640 v4l_print_ioctl(vfd->name, cmd);
641 printk(KERN_CONT "\n");
642 }
643
Hans Verkuil6a717882010-04-06 15:56:08 -0300644 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300645
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300646#ifdef CONFIG_VIDEO_V4L1_COMPAT
647 /***********************************************************
648 Handles calls to the obsoleted V4L1 API
649 Due to the nature of VIDIOCGMBUF, each driver that supports
650 V4L1 should implement its own handler for this ioctl.
651 ***********************************************************/
652
653 /* --- streaming capture ------------------------------------- */
Hans Verkuil6a717882010-04-06 15:56:08 -0300654 case VIDIOCGMBUF:
655 {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300656 struct video_mbuf *p = arg;
657
Hans Verkuila3998102008-07-21 02:57:38 -0300658 if (!ops->vidiocgmbuf)
Hans Verkuil6a717882010-04-06 15:56:08 -0300659 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300660 ret = ops->vidiocgmbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300661 if (!ret)
662 dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
663 p->size, p->frames,
664 (unsigned long)p->offsets);
Hans Verkuil6a717882010-04-06 15:56:08 -0300665 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300666 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300667#endif
668
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300669 /* --- capabilities ------------------------------------------ */
670 case VIDIOC_QUERYCAP:
671 {
672 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300673
Hans Verkuila3998102008-07-21 02:57:38 -0300674 if (!ops->vidioc_querycap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300675 break;
676
Hans Verkuila3998102008-07-21 02:57:38 -0300677 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300678 if (!ret)
679 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
680 "version=0x%08x, "
681 "capabilities=0x%08x\n",
682 cap->driver, cap->card, cap->bus_info,
683 cap->version,
684 cap->capabilities);
685 break;
686 }
687
688 /* --- priority ------------------------------------------ */
689 case VIDIOC_G_PRIORITY:
690 {
691 enum v4l2_priority *p = arg;
692
Hans Verkuila3998102008-07-21 02:57:38 -0300693 if (!ops->vidioc_g_priority)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300694 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300695 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300696 if (!ret)
697 dbgarg(cmd, "priority is %d\n", *p);
698 break;
699 }
700 case VIDIOC_S_PRIORITY:
701 {
702 enum v4l2_priority *p = arg;
703
Hans Verkuila3998102008-07-21 02:57:38 -0300704 if (!ops->vidioc_s_priority)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300705 break;
706 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuila3998102008-07-21 02:57:38 -0300707 ret = ops->vidioc_s_priority(file, fh, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300708 break;
709 }
710
711 /* --- capture ioctls ---------------------------------------- */
712 case VIDIOC_ENUM_FMT:
713 {
714 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300715
Trent Piepho19c96e42009-03-04 01:21:02 -0300716 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300717 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300718 if (ops->vidioc_enum_fmt_vid_cap)
719 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300720 break;
721 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300722 if (ops->vidioc_enum_fmt_vid_overlay)
723 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300724 fh, f);
725 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300726 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300727 if (ops->vidioc_enum_fmt_vid_out)
728 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300729 break;
730 case V4L2_BUF_TYPE_PRIVATE:
Hans Verkuila3998102008-07-21 02:57:38 -0300731 if (ops->vidioc_enum_fmt_type_private)
732 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300733 fh, f);
734 break;
735 default:
736 break;
737 }
738 if (!ret)
739 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
740 "pixelformat=%c%c%c%c, description='%s'\n",
741 f->index, f->type, f->flags,
742 (f->pixelformat & 0xff),
743 (f->pixelformat >> 8) & 0xff,
744 (f->pixelformat >> 16) & 0xff,
745 (f->pixelformat >> 24) & 0xff,
746 f->description);
747 break;
748 }
749 case VIDIOC_G_FMT:
750 {
751 struct v4l2_format *f = (struct v4l2_format *)arg;
752
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300753 /* FIXME: Should be one dump per type */
754 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
755
756 switch (f->type) {
757 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300758 if (ops->vidioc_g_fmt_vid_cap)
759 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300760 if (!ret)
761 v4l_print_pix_fmt(vfd, &f->fmt.pix);
762 break;
763 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300764 if (ops->vidioc_g_fmt_vid_overlay)
765 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300766 fh, f);
767 break;
768 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300769 if (ops->vidioc_g_fmt_vid_out)
770 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300771 if (!ret)
772 v4l_print_pix_fmt(vfd, &f->fmt.pix);
773 break;
774 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300775 if (ops->vidioc_g_fmt_vid_out_overlay)
776 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300777 fh, f);
778 break;
779 case V4L2_BUF_TYPE_VBI_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300780 if (ops->vidioc_g_fmt_vbi_cap)
781 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300782 break;
783 case V4L2_BUF_TYPE_VBI_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300784 if (ops->vidioc_g_fmt_vbi_out)
785 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300786 break;
787 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300788 if (ops->vidioc_g_fmt_sliced_vbi_cap)
789 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300790 fh, f);
791 break;
792 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300793 if (ops->vidioc_g_fmt_sliced_vbi_out)
794 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300795 fh, f);
796 break;
797 case V4L2_BUF_TYPE_PRIVATE:
Hans Verkuila3998102008-07-21 02:57:38 -0300798 if (ops->vidioc_g_fmt_type_private)
799 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300800 fh, f);
801 break;
802 }
803
804 break;
805 }
806 case VIDIOC_S_FMT:
807 {
808 struct v4l2_format *f = (struct v4l2_format *)arg;
809
810 /* FIXME: Should be one dump per type */
811 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
812
813 switch (f->type) {
814 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300815 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300816 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300817 if (ops->vidioc_s_fmt_vid_cap)
818 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300819 break;
820 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300821 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300822 if (ops->vidioc_s_fmt_vid_overlay)
823 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300824 fh, f);
825 break;
826 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300827 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300828 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300829 if (ops->vidioc_s_fmt_vid_out)
830 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300831 break;
832 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300833 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300834 if (ops->vidioc_s_fmt_vid_out_overlay)
835 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300836 fh, f);
837 break;
838 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300839 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300840 if (ops->vidioc_s_fmt_vbi_cap)
841 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300842 break;
843 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300844 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300845 if (ops->vidioc_s_fmt_vbi_out)
846 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300847 break;
848 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300849 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300850 if (ops->vidioc_s_fmt_sliced_vbi_cap)
851 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300852 fh, f);
853 break;
854 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300855 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300856 if (ops->vidioc_s_fmt_sliced_vbi_out)
857 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300858 fh, f);
859 break;
860 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300861 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Hans Verkuila3998102008-07-21 02:57:38 -0300862 if (ops->vidioc_s_fmt_type_private)
863 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300864 fh, f);
865 break;
866 }
867 break;
868 }
869 case VIDIOC_TRY_FMT:
870 {
871 struct v4l2_format *f = (struct v4l2_format *)arg;
872
873 /* FIXME: Should be one dump per type */
874 dbgarg(cmd, "type=%s\n", prt_names(f->type,
875 v4l2_type_names));
876 switch (f->type) {
877 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300878 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300879 if (ops->vidioc_try_fmt_vid_cap)
880 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300881 if (!ret)
882 v4l_print_pix_fmt(vfd, &f->fmt.pix);
883 break;
884 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300885 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300886 if (ops->vidioc_try_fmt_vid_overlay)
887 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300888 fh, f);
889 break;
890 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300891 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300892 if (ops->vidioc_try_fmt_vid_out)
893 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300894 if (!ret)
895 v4l_print_pix_fmt(vfd, &f->fmt.pix);
896 break;
897 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300898 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300899 if (ops->vidioc_try_fmt_vid_out_overlay)
900 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300901 fh, f);
902 break;
903 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300904 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300905 if (ops->vidioc_try_fmt_vbi_cap)
906 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300907 break;
908 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300909 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300910 if (ops->vidioc_try_fmt_vbi_out)
911 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300912 break;
913 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300914 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300915 if (ops->vidioc_try_fmt_sliced_vbi_cap)
916 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300917 fh, f);
918 break;
919 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300920 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300921 if (ops->vidioc_try_fmt_sliced_vbi_out)
922 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300923 fh, f);
924 break;
925 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300926 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Hans Verkuila3998102008-07-21 02:57:38 -0300927 if (ops->vidioc_try_fmt_type_private)
928 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300929 fh, f);
930 break;
931 }
932
933 break;
934 }
935 /* FIXME: Those buf reqs could be handled here,
936 with some changes on videobuf to allow its header to be included at
937 videodev2.h or being merged at videodev2.
938 */
939 case VIDIOC_REQBUFS:
940 {
941 struct v4l2_requestbuffers *p = arg;
942
Hans Verkuila3998102008-07-21 02:57:38 -0300943 if (!ops->vidioc_reqbufs)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300944 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300945 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300946 if (ret)
947 break;
948
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300949 if (p->type < V4L2_BUF_TYPE_PRIVATE)
950 CLEAR_AFTER_FIELD(p, memory);
951
Hans Verkuila3998102008-07-21 02:57:38 -0300952 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300953 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
954 p->count,
955 prt_names(p->type, v4l2_type_names),
956 prt_names(p->memory, v4l2_memory_names));
957 break;
958 }
959 case VIDIOC_QUERYBUF:
960 {
961 struct v4l2_buffer *p = arg;
962
Hans Verkuila3998102008-07-21 02:57:38 -0300963 if (!ops->vidioc_querybuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300964 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300965 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300966 if (ret)
967 break;
968
Hans Verkuila3998102008-07-21 02:57:38 -0300969 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300970 if (!ret)
971 dbgbuf(cmd, vfd, p);
972 break;
973 }
974 case VIDIOC_QBUF:
975 {
976 struct v4l2_buffer *p = arg;
977
Hans Verkuila3998102008-07-21 02:57:38 -0300978 if (!ops->vidioc_qbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300979 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300980 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300981 if (ret)
982 break;
983
Hans Verkuila3998102008-07-21 02:57:38 -0300984 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300985 if (!ret)
986 dbgbuf(cmd, vfd, p);
987 break;
988 }
989 case VIDIOC_DQBUF:
990 {
991 struct v4l2_buffer *p = arg;
992
Hans Verkuila3998102008-07-21 02:57:38 -0300993 if (!ops->vidioc_dqbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300994 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300995 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300996 if (ret)
997 break;
998
Hans Verkuila3998102008-07-21 02:57:38 -0300999 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001000 if (!ret)
1001 dbgbuf(cmd, vfd, p);
1002 break;
1003 }
1004 case VIDIOC_OVERLAY:
1005 {
1006 int *i = arg;
1007
Hans Verkuila3998102008-07-21 02:57:38 -03001008 if (!ops->vidioc_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001009 break;
1010 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001011 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001012 break;
1013 }
1014 case VIDIOC_G_FBUF:
1015 {
1016 struct v4l2_framebuffer *p = arg;
1017
Hans Verkuila3998102008-07-21 02:57:38 -03001018 if (!ops->vidioc_g_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001019 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001020 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001021 if (!ret) {
1022 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1023 p->capability, p->flags,
1024 (unsigned long)p->base);
1025 v4l_print_pix_fmt(vfd, &p->fmt);
1026 }
1027 break;
1028 }
1029 case VIDIOC_S_FBUF:
1030 {
1031 struct v4l2_framebuffer *p = arg;
1032
Hans Verkuila3998102008-07-21 02:57:38 -03001033 if (!ops->vidioc_s_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001034 break;
1035 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1036 p->capability, p->flags, (unsigned long)p->base);
1037 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -03001038 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001039 break;
1040 }
1041 case VIDIOC_STREAMON:
1042 {
1043 enum v4l2_buf_type i = *(int *)arg;
1044
Hans Verkuila3998102008-07-21 02:57:38 -03001045 if (!ops->vidioc_streamon)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001046 break;
1047 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001048 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001049 break;
1050 }
1051 case VIDIOC_STREAMOFF:
1052 {
1053 enum v4l2_buf_type i = *(int *)arg;
1054
Hans Verkuila3998102008-07-21 02:57:38 -03001055 if (!ops->vidioc_streamoff)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001056 break;
1057 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001058 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001059 break;
1060 }
1061 /* ---------- tv norms ---------- */
1062 case VIDIOC_ENUMSTD:
1063 {
1064 struct v4l2_standard *p = arg;
1065 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1066 unsigned int index = p->index, i, j = 0;
1067 const char *descr = "";
1068
1069 /* Return norm array in a canonical way */
1070 for (i = 0; i <= index && id; i++) {
1071 /* last std value in the standards array is 0, so this
1072 while always ends there since (id & 0) == 0. */
1073 while ((id & standards[j].std) != standards[j].std)
1074 j++;
1075 curr_id = standards[j].std;
1076 descr = standards[j].descr;
1077 j++;
1078 if (curr_id == 0)
1079 break;
1080 if (curr_id != V4L2_STD_PAL &&
1081 curr_id != V4L2_STD_SECAM &&
1082 curr_id != V4L2_STD_NTSC)
1083 id &= ~curr_id;
1084 }
1085 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001086 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001087
1088 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001089
1090 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1091 "framelines=%d\n", p->index,
1092 (unsigned long long)p->id, p->name,
1093 p->frameperiod.numerator,
1094 p->frameperiod.denominator,
1095 p->framelines);
1096
1097 ret = 0;
1098 break;
1099 }
1100 case VIDIOC_G_STD:
1101 {
1102 v4l2_std_id *id = arg;
1103
1104 ret = 0;
1105 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001106 if (ops->vidioc_g_std)
1107 ret = ops->vidioc_g_std(file, fh, id);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001108 else if (vfd->current_norm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001109 *id = vfd->current_norm;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001110 else
1111 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001112
1113 if (!ret)
1114 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1115 break;
1116 }
1117 case VIDIOC_S_STD:
1118 {
1119 v4l2_std_id *id = arg, norm;
1120
1121 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1122
1123 norm = (*id) & vfd->tvnorms;
1124 if (vfd->tvnorms && !norm) /* Check if std is supported */
1125 break;
1126
1127 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001128 if (ops->vidioc_s_std)
1129 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001130 else
1131 ret = -EINVAL;
1132
1133 /* Updates standard information */
1134 if (ret >= 0)
1135 vfd->current_norm = norm;
1136 break;
1137 }
1138 case VIDIOC_QUERYSTD:
1139 {
1140 v4l2_std_id *p = arg;
1141
Hans Verkuila3998102008-07-21 02:57:38 -03001142 if (!ops->vidioc_querystd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001143 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001144 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001145 if (!ret)
1146 dbgarg(cmd, "detected std=%08Lx\n",
1147 (unsigned long long)*p);
1148 break;
1149 }
1150 /* ------ input switching ---------- */
1151 /* FIXME: Inputs can be handled inside videodev2 */
1152 case VIDIOC_ENUMINPUT:
1153 {
1154 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001155
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001156 /*
1157 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1158 * CAP_STD here based on ioctl handler provided by the
1159 * driver. If the driver doesn't support these
1160 * for a specific input, it must override these flags.
1161 */
1162 if (ops->vidioc_s_std)
1163 p->capabilities |= V4L2_IN_CAP_STD;
1164 if (ops->vidioc_s_dv_preset)
1165 p->capabilities |= V4L2_IN_CAP_PRESETS;
1166 if (ops->vidioc_s_dv_timings)
1167 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1168
Hans Verkuila3998102008-07-21 02:57:38 -03001169 if (!ops->vidioc_enum_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001170 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001171
Hans Verkuila3998102008-07-21 02:57:38 -03001172 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001173 if (!ret)
1174 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1175 "audioset=%d, "
1176 "tuner=%d, std=%08Lx, status=%d\n",
1177 p->index, p->name, p->type, p->audioset,
1178 p->tuner,
1179 (unsigned long long)p->std,
1180 p->status);
1181 break;
1182 }
1183 case VIDIOC_G_INPUT:
1184 {
1185 unsigned int *i = arg;
1186
Hans Verkuila3998102008-07-21 02:57:38 -03001187 if (!ops->vidioc_g_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001188 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001189 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001190 if (!ret)
1191 dbgarg(cmd, "value=%d\n", *i);
1192 break;
1193 }
1194 case VIDIOC_S_INPUT:
1195 {
1196 unsigned int *i = arg;
1197
Hans Verkuila3998102008-07-21 02:57:38 -03001198 if (!ops->vidioc_s_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001199 break;
1200 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001201 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001202 break;
1203 }
1204
1205 /* ------ output switching ---------- */
1206 case VIDIOC_ENUMOUTPUT:
1207 {
1208 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001209
Hans Verkuila3998102008-07-21 02:57:38 -03001210 if (!ops->vidioc_enum_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001211 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001212
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001213 /*
1214 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1215 * CAP_STD here based on ioctl handler provided by the
1216 * driver. If the driver doesn't support these
1217 * for a specific output, it must override these flags.
1218 */
1219 if (ops->vidioc_s_std)
1220 p->capabilities |= V4L2_OUT_CAP_STD;
1221 if (ops->vidioc_s_dv_preset)
1222 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1223 if (ops->vidioc_s_dv_timings)
1224 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1225
Hans Verkuila3998102008-07-21 02:57:38 -03001226 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001227 if (!ret)
1228 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1229 "audioset=0x%x, "
1230 "modulator=%d, std=0x%08Lx\n",
1231 p->index, p->name, p->type, p->audioset,
1232 p->modulator, (unsigned long long)p->std);
1233 break;
1234 }
1235 case VIDIOC_G_OUTPUT:
1236 {
1237 unsigned int *i = arg;
1238
Hans Verkuila3998102008-07-21 02:57:38 -03001239 if (!ops->vidioc_g_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001240 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001241 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001242 if (!ret)
1243 dbgarg(cmd, "value=%d\n", *i);
1244 break;
1245 }
1246 case VIDIOC_S_OUTPUT:
1247 {
1248 unsigned int *i = arg;
1249
Hans Verkuila3998102008-07-21 02:57:38 -03001250 if (!ops->vidioc_s_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001251 break;
1252 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001253 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001254 break;
1255 }
1256
1257 /* --- controls ---------------------------------------------- */
1258 case VIDIOC_QUERYCTRL:
1259 {
1260 struct v4l2_queryctrl *p = arg;
1261
Hans Verkuila3998102008-07-21 02:57:38 -03001262 if (!ops->vidioc_queryctrl)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001263 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001264 ret = ops->vidioc_queryctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001265 if (!ret)
1266 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1267 "step=%d, default=%d, flags=0x%08x\n",
1268 p->id, p->type, p->name,
1269 p->minimum, p->maximum,
1270 p->step, p->default_value, p->flags);
1271 else
1272 dbgarg(cmd, "id=0x%x\n", p->id);
1273 break;
1274 }
1275 case VIDIOC_G_CTRL:
1276 {
1277 struct v4l2_control *p = arg;
1278
Hans Verkuila3998102008-07-21 02:57:38 -03001279 if (ops->vidioc_g_ctrl)
1280 ret = ops->vidioc_g_ctrl(file, fh, p);
1281 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001282 struct v4l2_ext_controls ctrls;
1283 struct v4l2_ext_control ctrl;
1284
1285 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1286 ctrls.count = 1;
1287 ctrls.controls = &ctrl;
1288 ctrl.id = p->id;
1289 ctrl.value = p->value;
1290 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001291 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001292 if (ret == 0)
1293 p->value = ctrl.value;
1294 }
1295 } else
1296 break;
1297 if (!ret)
1298 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1299 else
1300 dbgarg(cmd, "id=0x%x\n", p->id);
1301 break;
1302 }
1303 case VIDIOC_S_CTRL:
1304 {
1305 struct v4l2_control *p = arg;
1306 struct v4l2_ext_controls ctrls;
1307 struct v4l2_ext_control ctrl;
1308
Hans Verkuila3998102008-07-21 02:57:38 -03001309 if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001310 break;
1311
1312 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1313
Hans Verkuila3998102008-07-21 02:57:38 -03001314 if (ops->vidioc_s_ctrl) {
1315 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001316 break;
1317 }
Hans Verkuila3998102008-07-21 02:57:38 -03001318 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001319 break;
1320
1321 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1322 ctrls.count = 1;
1323 ctrls.controls = &ctrl;
1324 ctrl.id = p->id;
1325 ctrl.value = p->value;
1326 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001327 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001328 break;
1329 }
1330 case VIDIOC_G_EXT_CTRLS:
1331 {
1332 struct v4l2_ext_controls *p = arg;
1333
1334 p->error_idx = p->count;
Hans Verkuila3998102008-07-21 02:57:38 -03001335 if (!ops->vidioc_g_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001336 break;
1337 if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001338 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001339 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1340 break;
1341 }
1342 case VIDIOC_S_EXT_CTRLS:
1343 {
1344 struct v4l2_ext_controls *p = arg;
1345
1346 p->error_idx = p->count;
Hans Verkuila3998102008-07-21 02:57:38 -03001347 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001348 break;
1349 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1350 if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001351 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001352 break;
1353 }
1354 case VIDIOC_TRY_EXT_CTRLS:
1355 {
1356 struct v4l2_ext_controls *p = arg;
1357
1358 p->error_idx = p->count;
Hans Verkuila3998102008-07-21 02:57:38 -03001359 if (!ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001360 break;
1361 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1362 if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001363 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001364 break;
1365 }
1366 case VIDIOC_QUERYMENU:
1367 {
1368 struct v4l2_querymenu *p = arg;
1369
Hans Verkuila3998102008-07-21 02:57:38 -03001370 if (!ops->vidioc_querymenu)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001371 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001372 ret = ops->vidioc_querymenu(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001373 if (!ret)
1374 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1375 p->id, p->index, p->name);
1376 else
1377 dbgarg(cmd, "id=0x%x, index=%d\n",
1378 p->id, p->index);
1379 break;
1380 }
1381 /* --- audio ---------------------------------------------- */
1382 case VIDIOC_ENUMAUDIO:
1383 {
1384 struct v4l2_audio *p = arg;
1385
Hans Verkuila3998102008-07-21 02:57:38 -03001386 if (!ops->vidioc_enumaudio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001387 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001388 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001389 if (!ret)
1390 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1391 "mode=0x%x\n", p->index, p->name,
1392 p->capability, p->mode);
1393 else
1394 dbgarg(cmd, "index=%d\n", p->index);
1395 break;
1396 }
1397 case VIDIOC_G_AUDIO:
1398 {
1399 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001400
Hans Verkuila3998102008-07-21 02:57:38 -03001401 if (!ops->vidioc_g_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001402 break;
1403
Hans Verkuila3998102008-07-21 02:57:38 -03001404 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001405 if (!ret)
1406 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1407 "mode=0x%x\n", p->index,
1408 p->name, p->capability, p->mode);
1409 else
1410 dbgarg(cmd, "index=%d\n", p->index);
1411 break;
1412 }
1413 case VIDIOC_S_AUDIO:
1414 {
1415 struct v4l2_audio *p = arg;
1416
Hans Verkuila3998102008-07-21 02:57:38 -03001417 if (!ops->vidioc_s_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001418 break;
1419 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1420 "mode=0x%x\n", p->index, p->name,
1421 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001422 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001423 break;
1424 }
1425 case VIDIOC_ENUMAUDOUT:
1426 {
1427 struct v4l2_audioout *p = arg;
1428
Hans Verkuila3998102008-07-21 02:57:38 -03001429 if (!ops->vidioc_enumaudout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001430 break;
1431 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001432 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001433 if (!ret)
1434 dbgarg2("index=%d, name=%s, capability=%d, "
1435 "mode=%d\n", p->index, p->name,
1436 p->capability, p->mode);
1437 break;
1438 }
1439 case VIDIOC_G_AUDOUT:
1440 {
1441 struct v4l2_audioout *p = arg;
1442
Hans Verkuila3998102008-07-21 02:57:38 -03001443 if (!ops->vidioc_g_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001444 break;
Trent Piepho337f9d22009-03-04 01:21:02 -03001445
Hans Verkuila3998102008-07-21 02:57:38 -03001446 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001447 if (!ret)
1448 dbgarg2("index=%d, name=%s, capability=%d, "
1449 "mode=%d\n", p->index, p->name,
1450 p->capability, p->mode);
1451 break;
1452 }
1453 case VIDIOC_S_AUDOUT:
1454 {
1455 struct v4l2_audioout *p = arg;
1456
Hans Verkuila3998102008-07-21 02:57:38 -03001457 if (!ops->vidioc_s_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001458 break;
1459 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1460 "mode=%d\n", p->index, p->name,
1461 p->capability, p->mode);
1462
Hans Verkuila3998102008-07-21 02:57:38 -03001463 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001464 break;
1465 }
1466 case VIDIOC_G_MODULATOR:
1467 {
1468 struct v4l2_modulator *p = arg;
1469
Hans Verkuila3998102008-07-21 02:57:38 -03001470 if (!ops->vidioc_g_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001471 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001472 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001473 if (!ret)
1474 dbgarg(cmd, "index=%d, name=%s, "
1475 "capability=%d, rangelow=%d,"
1476 " rangehigh=%d, txsubchans=%d\n",
1477 p->index, p->name, p->capability,
1478 p->rangelow, p->rangehigh,
1479 p->txsubchans);
1480 break;
1481 }
1482 case VIDIOC_S_MODULATOR:
1483 {
1484 struct v4l2_modulator *p = arg;
1485
Hans Verkuila3998102008-07-21 02:57:38 -03001486 if (!ops->vidioc_s_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001487 break;
1488 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1489 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1490 p->index, p->name, p->capability, p->rangelow,
1491 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001492 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001493 break;
1494 }
1495 case VIDIOC_G_CROP:
1496 {
1497 struct v4l2_crop *p = arg;
1498
Hans Verkuila3998102008-07-21 02:57:38 -03001499 if (!ops->vidioc_g_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001500 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001501
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001502 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001503 ret = ops->vidioc_g_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001504 if (!ret)
1505 dbgrect(vfd, "", &p->c);
1506 break;
1507 }
1508 case VIDIOC_S_CROP:
1509 {
1510 struct v4l2_crop *p = arg;
1511
Hans Verkuila3998102008-07-21 02:57:38 -03001512 if (!ops->vidioc_s_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001513 break;
1514 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1515 dbgrect(vfd, "", &p->c);
Hans Verkuila3998102008-07-21 02:57:38 -03001516 ret = ops->vidioc_s_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001517 break;
1518 }
1519 case VIDIOC_CROPCAP:
1520 {
1521 struct v4l2_cropcap *p = arg;
1522
1523 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuila3998102008-07-21 02:57:38 -03001524 if (!ops->vidioc_cropcap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001525 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001526
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001527 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001528 ret = ops->vidioc_cropcap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001529 if (!ret) {
1530 dbgrect(vfd, "bounds ", &p->bounds);
1531 dbgrect(vfd, "defrect ", &p->defrect);
1532 }
1533 break;
1534 }
1535 case VIDIOC_G_JPEGCOMP:
1536 {
1537 struct v4l2_jpegcompression *p = arg;
1538
Hans Verkuila3998102008-07-21 02:57:38 -03001539 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001540 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001541
Hans Verkuila3998102008-07-21 02:57:38 -03001542 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001543 if (!ret)
1544 dbgarg(cmd, "quality=%d, APPn=%d, "
1545 "APP_len=%d, COM_len=%d, "
1546 "jpeg_markers=%d\n",
1547 p->quality, p->APPn, p->APP_len,
1548 p->COM_len, p->jpeg_markers);
1549 break;
1550 }
1551 case VIDIOC_S_JPEGCOMP:
1552 {
1553 struct v4l2_jpegcompression *p = arg;
1554
Hans Verkuila3998102008-07-21 02:57:38 -03001555 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001556 break;
1557 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1558 "COM_len=%d, jpeg_markers=%d\n",
1559 p->quality, p->APPn, p->APP_len,
1560 p->COM_len, p->jpeg_markers);
Hans Verkuila3998102008-07-21 02:57:38 -03001561 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001562 break;
1563 }
1564 case VIDIOC_G_ENC_INDEX:
1565 {
1566 struct v4l2_enc_idx *p = arg;
1567
Hans Verkuila3998102008-07-21 02:57:38 -03001568 if (!ops->vidioc_g_enc_index)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001569 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001570 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001571 if (!ret)
1572 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1573 p->entries, p->entries_cap);
1574 break;
1575 }
1576 case VIDIOC_ENCODER_CMD:
1577 {
1578 struct v4l2_encoder_cmd *p = arg;
1579
Hans Verkuila3998102008-07-21 02:57:38 -03001580 if (!ops->vidioc_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001581 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001582 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001583 if (!ret)
1584 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1585 break;
1586 }
1587 case VIDIOC_TRY_ENCODER_CMD:
1588 {
1589 struct v4l2_encoder_cmd *p = arg;
1590
Hans Verkuila3998102008-07-21 02:57:38 -03001591 if (!ops->vidioc_try_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001592 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001593 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001594 if (!ret)
1595 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1596 break;
1597 }
1598 case VIDIOC_G_PARM:
1599 {
1600 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001601
Hans Verkuila3998102008-07-21 02:57:38 -03001602 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001603 ret = check_fmt(ops, p->type);
1604 if (ret)
1605 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001606 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001607 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001608 v4l2_std_id std = vfd->current_norm;
1609
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001610 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001611 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001612
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001613 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001614 if (ops->vidioc_g_std)
1615 ret = ops->vidioc_g_std(file, fh, &std);
1616 else if (std == 0)
1617 ret = -EINVAL;
1618 if (ret == 0)
1619 v4l2_video_std_frame_period(std,
1620 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001621 }
1622
1623 dbgarg(cmd, "type=%d\n", p->type);
1624 break;
1625 }
1626 case VIDIOC_S_PARM:
1627 {
1628 struct v4l2_streamparm *p = arg;
1629
Hans Verkuila3998102008-07-21 02:57:38 -03001630 if (!ops->vidioc_s_parm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001631 break;
Trent Piepho34796bc2009-03-28 22:25:35 -03001632 ret = check_fmt(ops, p->type);
1633 if (ret)
1634 break;
1635
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001636 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001637 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001638 break;
1639 }
1640 case VIDIOC_G_TUNER:
1641 {
1642 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001643
Hans Verkuila3998102008-07-21 02:57:38 -03001644 if (!ops->vidioc_g_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001645 break;
1646
Hans Verkuila3998102008-07-21 02:57:38 -03001647 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001648 if (!ret)
1649 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1650 "capability=0x%x, rangelow=%d, "
1651 "rangehigh=%d, signal=%d, afc=%d, "
1652 "rxsubchans=0x%x, audmode=%d\n",
1653 p->index, p->name, p->type,
1654 p->capability, p->rangelow,
1655 p->rangehigh, p->signal, p->afc,
1656 p->rxsubchans, p->audmode);
1657 break;
1658 }
1659 case VIDIOC_S_TUNER:
1660 {
1661 struct v4l2_tuner *p = arg;
1662
Hans Verkuila3998102008-07-21 02:57:38 -03001663 if (!ops->vidioc_s_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001664 break;
1665 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1666 "capability=0x%x, rangelow=%d, "
1667 "rangehigh=%d, signal=%d, afc=%d, "
1668 "rxsubchans=0x%x, audmode=%d\n",
1669 p->index, p->name, p->type,
1670 p->capability, p->rangelow,
1671 p->rangehigh, p->signal, p->afc,
1672 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001673 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001674 break;
1675 }
1676 case VIDIOC_G_FREQUENCY:
1677 {
1678 struct v4l2_frequency *p = arg;
1679
Hans Verkuila3998102008-07-21 02:57:38 -03001680 if (!ops->vidioc_g_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001681 break;
1682
Hans Verkuila3998102008-07-21 02:57:38 -03001683 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001684 if (!ret)
1685 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1686 p->tuner, p->type, p->frequency);
1687 break;
1688 }
1689 case VIDIOC_S_FREQUENCY:
1690 {
1691 struct v4l2_frequency *p = arg;
1692
Hans Verkuila3998102008-07-21 02:57:38 -03001693 if (!ops->vidioc_s_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001694 break;
1695 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1696 p->tuner, p->type, p->frequency);
Hans Verkuila3998102008-07-21 02:57:38 -03001697 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001698 break;
1699 }
1700 case VIDIOC_G_SLICED_VBI_CAP:
1701 {
1702 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001703
Hans Verkuila3998102008-07-21 02:57:38 -03001704 if (!ops->vidioc_g_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001705 break;
Trent Piepho19c96e42009-03-04 01:21:02 -03001706
1707 /* Clear up to type, everything after type is zerod already */
1708 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1709
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001710 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001711 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001712 if (!ret)
1713 dbgarg2("service_set=%d\n", p->service_set);
1714 break;
1715 }
1716 case VIDIOC_LOG_STATUS:
1717 {
Hans Verkuila3998102008-07-21 02:57:38 -03001718 if (!ops->vidioc_log_status)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001719 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001720 ret = ops->vidioc_log_status(file, fh);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001721 break;
1722 }
1723#ifdef CONFIG_VIDEO_ADV_DEBUG
1724 case VIDIOC_DBG_G_REGISTER:
1725 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001726 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001727
1728 if (!capable(CAP_SYS_ADMIN))
1729 ret = -EPERM;
Hans Verkuila3998102008-07-21 02:57:38 -03001730 else if (ops->vidioc_g_register)
1731 ret = ops->vidioc_g_register(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001732 break;
1733 }
1734 case VIDIOC_DBG_S_REGISTER:
1735 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001736 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001737
1738 if (!capable(CAP_SYS_ADMIN))
1739 ret = -EPERM;
Hans Verkuila3998102008-07-21 02:57:38 -03001740 else if (ops->vidioc_s_register)
1741 ret = ops->vidioc_s_register(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001742 break;
1743 }
1744#endif
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001745 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001746 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001747 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001748
Hans Verkuila3998102008-07-21 02:57:38 -03001749 if (!ops->vidioc_g_chip_ident)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001750 break;
Hans Verkuil80b36e02009-02-07 11:00:02 -03001751 p->ident = V4L2_IDENT_NONE;
1752 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001753 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001754 if (!ret)
1755 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1756 break;
1757 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001758 case VIDIOC_S_HW_FREQ_SEEK:
1759 {
1760 struct v4l2_hw_freq_seek *p = arg;
1761
Hans Verkuila3998102008-07-21 02:57:38 -03001762 if (!ops->vidioc_s_hw_freq_seek)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001763 break;
1764 dbgarg(cmd,
1765 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1766 p->tuner, p->type, p->seek_upward, p->wrap_around);
Hans Verkuila3998102008-07-21 02:57:38 -03001767 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1768 break;
1769 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001770 case VIDIOC_ENUM_FRAMESIZES:
1771 {
1772 struct v4l2_frmsizeenum *p = arg;
1773
1774 if (!ops->vidioc_enum_framesizes)
1775 break;
1776
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001777 ret = ops->vidioc_enum_framesizes(file, fh, p);
1778 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001779 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1780 p->index,
1781 (p->pixel_format & 0xff),
1782 (p->pixel_format >> 8) & 0xff,
1783 (p->pixel_format >> 16) & 0xff,
1784 (p->pixel_format >> 24) & 0xff,
1785 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001786 switch (p->type) {
1787 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001788 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001789 p->discrete.width, p->discrete.height);
1790 break;
1791 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001792 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001793 p->stepwise.min_width, p->stepwise.min_height,
1794 p->stepwise.step_width, p->stepwise.step_height,
1795 p->stepwise.max_width, p->stepwise.max_height);
1796 break;
1797 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001798 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001799 break;
1800 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001801 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001802 }
1803
1804 break;
1805 }
1806 case VIDIOC_ENUM_FRAMEINTERVALS:
1807 {
1808 struct v4l2_frmivalenum *p = arg;
1809
1810 if (!ops->vidioc_enum_frameintervals)
1811 break;
1812
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001813 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1814 dbgarg(cmd,
1815 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1816 p->index, p->pixel_format,
1817 p->width, p->height, p->type);
1818 switch (p->type) {
1819 case V4L2_FRMIVAL_TYPE_DISCRETE:
1820 dbgarg2("fps=%d/%d\n",
1821 p->discrete.numerator,
1822 p->discrete.denominator);
1823 break;
1824 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001825 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1826 p->stepwise.min.numerator,
1827 p->stepwise.min.denominator,
1828 p->stepwise.max.numerator,
1829 p->stepwise.max.denominator,
1830 p->stepwise.step.numerator,
1831 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001832 break;
1833 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1834 dbgarg2("continuous\n");
1835 break;
1836 default:
1837 dbgarg2("- Unknown type!\n");
1838 }
1839 break;
1840 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001841 case VIDIOC_ENUM_DV_PRESETS:
1842 {
1843 struct v4l2_dv_enum_preset *p = arg;
1844
1845 if (!ops->vidioc_enum_dv_presets)
1846 break;
1847
1848 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1849 if (!ret)
1850 dbgarg(cmd,
1851 "index=%d, preset=%d, name=%s, width=%d,"
1852 " height=%d ",
1853 p->index, p->preset, p->name, p->width,
1854 p->height);
1855 break;
1856 }
1857 case VIDIOC_S_DV_PRESET:
1858 {
1859 struct v4l2_dv_preset *p = arg;
1860
1861 if (!ops->vidioc_s_dv_preset)
1862 break;
1863
1864 dbgarg(cmd, "preset=%d\n", p->preset);
1865 ret = ops->vidioc_s_dv_preset(file, fh, p);
1866 break;
1867 }
1868 case VIDIOC_G_DV_PRESET:
1869 {
1870 struct v4l2_dv_preset *p = arg;
1871
1872 if (!ops->vidioc_g_dv_preset)
1873 break;
1874
1875 ret = ops->vidioc_g_dv_preset(file, fh, p);
1876 if (!ret)
1877 dbgarg(cmd, "preset=%d\n", p->preset);
1878 break;
1879 }
1880 case VIDIOC_QUERY_DV_PRESET:
1881 {
1882 struct v4l2_dv_preset *p = arg;
1883
1884 if (!ops->vidioc_query_dv_preset)
1885 break;
1886
1887 ret = ops->vidioc_query_dv_preset(file, fh, p);
1888 if (!ret)
1889 dbgarg(cmd, "preset=%d\n", p->preset);
1890 break;
1891 }
1892 case VIDIOC_S_DV_TIMINGS:
1893 {
1894 struct v4l2_dv_timings *p = arg;
1895
1896 if (!ops->vidioc_s_dv_timings)
1897 break;
1898
1899 switch (p->type) {
1900 case V4L2_DV_BT_656_1120:
1901 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
1902 " width=%d, height=%d, polarities=%x,"
1903 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
1904 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
1905 " il_vfrontporch=%d, il_vsync=%d,"
1906 " il_vbackporch=%d\n",
1907 p->bt.interlaced, p->bt.pixelclock,
1908 p->bt.width, p->bt.height, p->bt.polarities,
1909 p->bt.hfrontporch, p->bt.hsync,
1910 p->bt.hbackporch, p->bt.vfrontporch,
1911 p->bt.vsync, p->bt.vbackporch,
1912 p->bt.il_vfrontporch, p->bt.il_vsync,
1913 p->bt.il_vbackporch);
1914 ret = ops->vidioc_s_dv_timings(file, fh, p);
1915 break;
1916 default:
1917 dbgarg2("Unknown type %d!\n", p->type);
1918 break;
1919 }
1920 break;
1921 }
1922 case VIDIOC_G_DV_TIMINGS:
1923 {
1924 struct v4l2_dv_timings *p = arg;
1925
1926 if (!ops->vidioc_g_dv_timings)
1927 break;
1928
1929 ret = ops->vidioc_g_dv_timings(file, fh, p);
1930 if (!ret) {
1931 switch (p->type) {
1932 case V4L2_DV_BT_656_1120:
1933 dbgarg2("bt-656/1120:interlaced=%d,"
1934 " pixelclock=%lld,"
1935 " width=%d, height=%d, polarities=%x,"
1936 " hfrontporch=%d, hsync=%d,"
1937 " hbackporch=%d, vfrontporch=%d,"
1938 " vsync=%d, vbackporch=%d,"
1939 " il_vfrontporch=%d, il_vsync=%d,"
1940 " il_vbackporch=%d\n",
1941 p->bt.interlaced, p->bt.pixelclock,
1942 p->bt.width, p->bt.height,
1943 p->bt.polarities, p->bt.hfrontporch,
1944 p->bt.hsync, p->bt.hbackporch,
1945 p->bt.vfrontporch, p->bt.vsync,
1946 p->bt.vbackporch, p->bt.il_vfrontporch,
1947 p->bt.il_vsync, p->bt.il_vbackporch);
1948 break;
1949 default:
1950 dbgarg2("Unknown type %d!\n", p->type);
1951 break;
1952 }
1953 }
1954 break;
1955 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03001956 case VIDIOC_DQEVENT:
1957 {
1958 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001959
Sakari Ailusd3d7c962010-03-27 11:02:10 -03001960 if (!ops->vidioc_subscribe_event)
1961 break;
1962
1963 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
1964 if (ret < 0) {
1965 dbgarg(cmd, "no pending events?");
1966 break;
1967 }
1968 dbgarg(cmd,
1969 "pending=%d, type=0x%8.8x, sequence=%d, "
1970 "timestamp=%lu.%9.9lu ",
1971 ev->pending, ev->type, ev->sequence,
1972 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
1973 break;
1974 }
1975 case VIDIOC_SUBSCRIBE_EVENT:
1976 {
1977 struct v4l2_event_subscription *sub = arg;
1978
1979 if (!ops->vidioc_subscribe_event)
1980 break;
1981
1982 ret = ops->vidioc_subscribe_event(fh, sub);
1983 if (ret < 0) {
1984 dbgarg(cmd, "failed, ret=%ld", ret);
1985 break;
1986 }
1987 dbgarg(cmd, "type=0x%8.8x", sub->type);
1988 break;
1989 }
1990 case VIDIOC_UNSUBSCRIBE_EVENT:
1991 {
1992 struct v4l2_event_subscription *sub = arg;
1993
1994 if (!ops->vidioc_unsubscribe_event)
1995 break;
1996
1997 ret = ops->vidioc_unsubscribe_event(fh, sub);
1998 if (ret < 0) {
1999 dbgarg(cmd, "failed, ret=%ld", ret);
2000 break;
2001 }
2002 dbgarg(cmd, "type=0x%8.8x", sub->type);
2003 break;
2004 }
Hans Verkuila3998102008-07-21 02:57:38 -03002005 default:
2006 {
2007 if (!ops->vidioc_default)
2008 break;
2009 ret = ops->vidioc_default(file, fh, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002010 break;
2011 }
2012 } /* switch */
2013
2014 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2015 if (ret < 0) {
2016 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002017 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002018 }
2019 }
2020
2021 return ret;
2022}
2023
Trent Piepho19c96e42009-03-04 01:21:02 -03002024/* In some cases, only a few fields are used as input, i.e. when the app sets
2025 * "index" and then the driver fills in the rest of the structure for the thing
2026 * with that index. We only need to copy up the first non-input field. */
2027static unsigned long cmd_input_size(unsigned int cmd)
2028{
2029 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002030#define CMDINSIZE(cmd, type, field) \
2031 case VIDIOC_##cmd: \
2032 return offsetof(struct v4l2_##type, field) + \
2033 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002034
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002035 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002036 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2037 CMDINSIZE(G_FMT, format, type);
2038 CMDINSIZE(QUERYBUF, buffer, type);
2039 CMDINSIZE(G_PARM, streamparm, type);
2040 CMDINSIZE(ENUMSTD, standard, index);
2041 CMDINSIZE(ENUMINPUT, input, index);
2042 CMDINSIZE(G_CTRL, control, id);
2043 CMDINSIZE(G_TUNER, tuner, index);
2044 CMDINSIZE(QUERYCTRL, queryctrl, id);
2045 CMDINSIZE(QUERYMENU, querymenu, index);
2046 CMDINSIZE(ENUMOUTPUT, output, index);
2047 CMDINSIZE(G_MODULATOR, modulator, index);
2048 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2049 CMDINSIZE(CROPCAP, cropcap, type);
2050 CMDINSIZE(G_CROP, crop, type);
2051 CMDINSIZE(ENUMAUDIO, audio, index);
2052 CMDINSIZE(ENUMAUDOUT, audioout, index);
2053 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2054 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2055 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2056 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2057 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2058 default:
2059 return _IOC_SIZE(cmd);
2060 }
2061}
2062
Hans Verkuil069b7472008-12-30 07:04:34 -03002063long video_ioctl2(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002064 unsigned int cmd, unsigned long arg)
2065{
2066 char sbuf[128];
2067 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002068 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002069 long err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002070 int is_ext_ctrl;
2071 size_t ctrls_size = 0;
2072 void __user *user_ptr = NULL;
2073
2074#ifdef __OLD_VIDIOC_
2075 cmd = video_fix_command(cmd);
2076#endif
2077 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
2078 cmd == VIDIOC_TRY_EXT_CTRLS);
2079
2080 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002081 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002082 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2083 parg = sbuf;
2084 } else {
2085 /* too big to allocate from stack */
2086 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2087 if (NULL == mbuf)
2088 return -ENOMEM;
2089 parg = mbuf;
2090 }
2091
2092 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002093 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2094 unsigned long n = cmd_input_size(cmd);
2095
2096 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002097 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002098
2099 /* zero out anything we don't copy from userspace */
2100 if (n < _IOC_SIZE(cmd))
2101 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002102 } else {
2103 /* read-only ioctl */
2104 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002105 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002106 }
2107
2108 if (is_ext_ctrl) {
2109 struct v4l2_ext_controls *p = parg;
2110
2111 /* In case of an error, tell the caller that it wasn't
2112 a specific control that caused it. */
2113 p->error_idx = p->count;
2114 user_ptr = (void __user *)p->controls;
2115 if (p->count) {
2116 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
2117 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
2118 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
2119 err = -ENOMEM;
2120 if (NULL == mbuf)
2121 goto out_ext_ctrl;
2122 err = -EFAULT;
2123 if (copy_from_user(mbuf, user_ptr, ctrls_size))
2124 goto out_ext_ctrl;
2125 p->controls = mbuf;
2126 }
2127 }
2128
2129 /* Handles IOCTL */
Mauro Carvalho Chehabb1f88402008-10-21 11:27:20 -03002130 err = __video_do_ioctl(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002131 if (err == -ENOIOCTLCMD)
2132 err = -EINVAL;
2133 if (is_ext_ctrl) {
2134 struct v4l2_ext_controls *p = parg;
2135
2136 p->controls = (void *)user_ptr;
2137 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
2138 err = -EFAULT;
2139 goto out_ext_ctrl;
2140 }
2141 if (err < 0)
2142 goto out;
2143
2144out_ext_ctrl:
2145 /* Copy results into user buffer */
2146 switch (_IOC_DIR(cmd)) {
2147 case _IOC_READ:
2148 case (_IOC_WRITE | _IOC_READ):
2149 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2150 err = -EFAULT;
2151 break;
2152 }
2153
2154out:
2155 kfree(mbuf);
2156 return err;
2157}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002158EXPORT_SYMBOL(video_ioctl2);