blob: a0089bf7a249481f194f7c3ee1e2703d92636328 [file] [log] [blame]
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic framework to process V4L2 ioctl commands.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
Alan Coxd9b01442008-10-27 15:13:47 -030011 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
Hans Verkuil35ea11f2008-07-20 08:12:02 -030012 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
13 */
14
15#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030017#include <linux/types.h>
18#include <linux/kernel.h>
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -030019#include <linux/version.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030020
Hans Verkuil35ea11f2008-07-20 08:12:02 -030021#include <linux/videodev2.h>
22
Hans Verkuil35ea11f2008-07-20 08:12:02 -030023#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
Hans Verkuil11bbc1c2010-05-16 09:24:06 -030025#include <media/v4l2-ctrls.h>
Sakari Ailusd3d7c962010-03-27 11:02:10 -030026#include <media/v4l2-fh.h>
27#include <media/v4l2-event.h>
Hans Verkuil99cd47bc2011-03-11 19:00:56 -030028#include <media/v4l2-device.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030029#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030
31#define dbgarg(cmd, fmt, arg...) \
32 do { \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
37 } \
38 } while (0)
39
40#define dbgarg2(fmt, arg...) \
41 do { \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
44 } while (0)
45
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030046#define dbgarg3(fmt, arg...) \
47 do { \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
50 } while (0)
51
Lucas De Marchi25985ed2011-03-30 22:57:33 -030052/* Zero out the end of the struct pointed to by p. Everything after, but
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030053 * not including, the specified field is cleared. */
54#define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
57
Hans Verkuil93d5a302011-08-09 09:32:06 -030058#define have_fmt_ops(foo) ( \
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -030059 ops->vidioc_##foo##_fmt_vid_cap || \
60 ops->vidioc_##foo##_fmt_vid_out || \
61 ops->vidioc_##foo##_fmt_vid_cap_mplane || \
62 ops->vidioc_##foo##_fmt_vid_out_mplane || \
63 ops->vidioc_##foo##_fmt_vid_overlay || \
Hans Verkuil93d5a302011-08-09 09:32:06 -030064 ops->vidioc_##foo##_fmt_vbi_cap || \
65 ops->vidioc_##foo##_fmt_vid_out_overlay || \
66 ops->vidioc_##foo##_fmt_vbi_out || \
67 ops->vidioc_##foo##_fmt_sliced_vbi_cap || \
68 ops->vidioc_##foo##_fmt_sliced_vbi_out || \
69 ops->vidioc_##foo##_fmt_type_private)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -030070
Hans Verkuil35ea11f2008-07-20 08:12:02 -030071struct std_descr {
72 v4l2_std_id std;
73 const char *descr;
74};
75
76static const struct std_descr standards[] = {
77 { V4L2_STD_NTSC, "NTSC" },
78 { V4L2_STD_NTSC_M, "NTSC-M" },
79 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
80 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
81 { V4L2_STD_NTSC_443, "NTSC-443" },
82 { V4L2_STD_PAL, "PAL" },
83 { V4L2_STD_PAL_BG, "PAL-BG" },
84 { V4L2_STD_PAL_B, "PAL-B" },
85 { V4L2_STD_PAL_B1, "PAL-B1" },
86 { V4L2_STD_PAL_G, "PAL-G" },
87 { V4L2_STD_PAL_H, "PAL-H" },
88 { V4L2_STD_PAL_I, "PAL-I" },
89 { V4L2_STD_PAL_DK, "PAL-DK" },
90 { V4L2_STD_PAL_D, "PAL-D" },
91 { V4L2_STD_PAL_D1, "PAL-D1" },
92 { V4L2_STD_PAL_K, "PAL-K" },
93 { V4L2_STD_PAL_M, "PAL-M" },
94 { V4L2_STD_PAL_N, "PAL-N" },
95 { V4L2_STD_PAL_Nc, "PAL-Nc" },
96 { V4L2_STD_PAL_60, "PAL-60" },
97 { V4L2_STD_SECAM, "SECAM" },
98 { V4L2_STD_SECAM_B, "SECAM-B" },
99 { V4L2_STD_SECAM_G, "SECAM-G" },
100 { V4L2_STD_SECAM_H, "SECAM-H" },
101 { V4L2_STD_SECAM_DK, "SECAM-DK" },
102 { V4L2_STD_SECAM_D, "SECAM-D" },
103 { V4L2_STD_SECAM_K, "SECAM-K" },
104 { V4L2_STD_SECAM_K1, "SECAM-K1" },
105 { V4L2_STD_SECAM_L, "SECAM-L" },
106 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
107 { 0, "Unknown" }
108};
109
110/* video4linux standard ID conversion to standard name
111 */
112const char *v4l2_norm_to_name(v4l2_std_id id)
113{
114 u32 myid = id;
115 int i;
116
117 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
118 64 bit comparations. So, on that architecture, with some gcc
119 variants, compilation fails. Currently, the max value is 30bit wide.
120 */
121 BUG_ON(myid != id);
122
123 for (i = 0; standards[i].std; i++)
124 if (myid == standards[i].std)
125 break;
126 return standards[i].descr;
127}
128EXPORT_SYMBOL(v4l2_norm_to_name);
129
Trent Piepho51f0b8d2009-03-04 01:21:02 -0300130/* Returns frame period for the given standard */
131void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
132{
133 if (id & V4L2_STD_525_60) {
134 frameperiod->numerator = 1001;
135 frameperiod->denominator = 30000;
136 } else {
137 frameperiod->numerator = 1;
138 frameperiod->denominator = 25;
139 }
140}
141EXPORT_SYMBOL(v4l2_video_std_frame_period);
142
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300143/* Fill in the fields of a v4l2_standard structure according to the
144 'id' and 'transmission' parameters. Returns negative on error. */
145int v4l2_video_std_construct(struct v4l2_standard *vs,
146 int id, const char *name)
147{
Trent Piepho51f0b8d2009-03-04 01:21:02 -0300148 vs->id = id;
149 v4l2_video_std_frame_period(id, &vs->frameperiod);
150 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300151 strlcpy(vs->name, name, sizeof(vs->name));
152 return 0;
153}
154EXPORT_SYMBOL(v4l2_video_std_construct);
155
156/* ----------------------------------------------------------------- */
157/* some arrays for pretty-printing debug messages of enum types */
158
159const char *v4l2_field_names[] = {
160 [V4L2_FIELD_ANY] = "any",
161 [V4L2_FIELD_NONE] = "none",
162 [V4L2_FIELD_TOP] = "top",
163 [V4L2_FIELD_BOTTOM] = "bottom",
164 [V4L2_FIELD_INTERLACED] = "interlaced",
165 [V4L2_FIELD_SEQ_TB] = "seq-tb",
166 [V4L2_FIELD_SEQ_BT] = "seq-bt",
167 [V4L2_FIELD_ALTERNATE] = "alternate",
168 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
169 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
170};
171EXPORT_SYMBOL(v4l2_field_names);
172
173const char *v4l2_type_names[] = {
174 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
175 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
176 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
177 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
178 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
179 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
180 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
181 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300182 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
183 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300184};
185EXPORT_SYMBOL(v4l2_type_names);
186
187static const char *v4l2_memory_names[] = {
188 [V4L2_MEMORY_MMAP] = "mmap",
189 [V4L2_MEMORY_USERPTR] = "userptr",
190 [V4L2_MEMORY_OVERLAY] = "overlay",
191};
192
193#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
194 arr[a] : "unknown")
195
196/* ------------------------------------------------------------------ */
197/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300198static const char *v4l2_ioctls[] = {
199 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
200 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
201 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
202 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
203 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
204 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
205 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
206 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
207 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
208 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
209 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
210 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
211 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
212 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
213 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
214 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
215 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
216 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
217 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
218 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
219 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
220 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
221 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
222 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
223 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
224 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
225 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
226 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
227 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
228 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
229 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
230 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
231 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
232 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
233 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
234 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
235 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
236 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
237 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
238 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
239 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
240 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
241 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
242 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
243 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
244 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
245 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
246 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
247 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
248 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
249 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
250 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
251 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
252 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
253 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
254#if 1
255 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
256 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
257 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
258 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
259 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
260
261 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
262 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
263
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300264 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300265 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
266#endif
Muralidharan Karicherib6456c02009-11-19 12:00:31 -0300267 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS",
268 [_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET",
269 [_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET",
270 [_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET",
271 [_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS",
272 [_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS",
Sakari Ailusfda10212010-02-24 19:19:05 -0300273 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
274 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
275 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300276};
277#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
278
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300279/* Common ioctl debug function. This function can be used by
280 external ioctl messages as well as internal V4L ioctl */
281void v4l_printk_ioctl(unsigned int cmd)
282{
283 char *dir, *type;
284
285 switch (_IOC_TYPE(cmd)) {
286 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300287 type = "v4l2_int";
288 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300289 case 'V':
290 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
291 type = "v4l2";
292 break;
293 }
294 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
295 return;
296 default:
297 type = "unknown";
298 }
299
300 switch (_IOC_DIR(cmd)) {
301 case _IOC_NONE: dir = "--"; break;
302 case _IOC_READ: dir = "r-"; break;
303 case _IOC_WRITE: dir = "-w"; break;
304 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
305 default: dir = "*ERR*"; break;
306 }
307 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
308 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
309}
310EXPORT_SYMBOL(v4l_printk_ioctl);
311
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300312static void dbgbuf(unsigned int cmd, struct video_device *vfd,
313 struct v4l2_buffer *p)
314{
315 struct v4l2_timecode *tc = &p->timecode;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300316 struct v4l2_plane *plane;
317 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300318
319 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300320 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300321 p->timestamp.tv_sec / 3600,
322 (int)(p->timestamp.tv_sec / 60) % 60,
323 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300324 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300325 p->index,
326 prt_names(p->type, v4l2_type_names),
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300327 p->flags, p->field, p->sequence,
328 prt_names(p->memory, v4l2_memory_names));
329
330 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
331 for (i = 0; i < p->length; ++i) {
332 plane = &p->m.planes[i];
333 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
334 "offset/userptr=0x%08lx, length=%d\n",
335 i, plane->bytesused, plane->data_offset,
336 plane->m.userptr, plane->length);
337 }
338 } else {
339 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
340 p->bytesused, p->m.userptr, p->length);
341 }
342
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300343 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
344 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
345 tc->hours, tc->minutes, tc->seconds,
346 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
347}
348
349static inline void dbgrect(struct video_device *vfd, char *s,
350 struct v4l2_rect *r)
351{
352 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
353 r->width, r->height);
354};
355
356static inline void v4l_print_pix_fmt(struct video_device *vfd,
357 struct v4l2_pix_format *fmt)
358{
359 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
360 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
361 fmt->width, fmt->height,
362 (fmt->pixelformat & 0xff),
363 (fmt->pixelformat >> 8) & 0xff,
364 (fmt->pixelformat >> 16) & 0xff,
365 (fmt->pixelformat >> 24) & 0xff,
366 prt_names(fmt->field, v4l2_field_names),
367 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
368};
369
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300370static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
371 struct v4l2_pix_format_mplane *fmt)
372{
373 int i;
374
375 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
376 "colorspace=%d, num_planes=%d\n",
377 fmt->width, fmt->height,
378 (fmt->pixelformat & 0xff),
379 (fmt->pixelformat >> 8) & 0xff,
380 (fmt->pixelformat >> 16) & 0xff,
381 (fmt->pixelformat >> 24) & 0xff,
382 prt_names(fmt->field, v4l2_field_names),
383 fmt->colorspace, fmt->num_planes);
384
385 for (i = 0; i < fmt->num_planes; ++i)
386 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
387 fmt->plane_fmt[i].bytesperline,
388 fmt->plane_fmt[i].sizeimage);
389}
390
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300391static inline void v4l_print_ext_ctrls(unsigned int cmd,
392 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
393{
394 __u32 i;
395
396 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
397 return;
398 dbgarg(cmd, "");
399 printk(KERN_CONT "class=0x%x", c->ctrl_class);
400 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300401 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300402 printk(KERN_CONT " id/val=0x%x/0x%x",
403 c->controls[i].id, c->controls[i].value);
404 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300405 printk(KERN_CONT " id=0x%x,size=%u",
406 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300407 }
408 printk(KERN_CONT "\n");
409};
410
411static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
412{
413 __u32 i;
414
415 /* zero the reserved fields */
416 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300417 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300418 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300419
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300420 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
421 when using extended controls.
422 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
423 is it allowed for backwards compatibility.
424 */
425 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
426 return 0;
427 /* Check that all controls are from the same control class. */
428 for (i = 0; i < c->count; i++) {
429 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
430 c->error_idx = i;
431 return 0;
432 }
433 }
434 return 1;
435}
436
Hans Verkuila3998102008-07-21 02:57:38 -0300437static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300438{
Hans Verkuila3998102008-07-21 02:57:38 -0300439 if (ops == NULL)
440 return -EINVAL;
441
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300442 switch (type) {
443 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300444 if (ops->vidioc_g_fmt_vid_cap ||
445 ops->vidioc_g_fmt_vid_cap_mplane)
446 return 0;
447 break;
448 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
449 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300450 return 0;
451 break;
452 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300453 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300454 return 0;
455 break;
456 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300457 if (ops->vidioc_g_fmt_vid_out ||
458 ops->vidioc_g_fmt_vid_out_mplane)
459 return 0;
460 break;
461 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
462 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300463 return 0;
464 break;
465 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300466 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300467 return 0;
468 break;
469 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300470 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300471 return 0;
472 break;
473 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300474 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300475 return 0;
476 break;
477 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300478 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300479 return 0;
480 break;
481 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300482 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300483 return 0;
484 break;
485 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300486 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300487 return 0;
488 break;
489 }
490 return -EINVAL;
491}
492
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300493/**
494 * fmt_sp_to_mp() - Convert a single-plane format to its multi-planar 1-plane
495 * equivalent
496 */
497static int fmt_sp_to_mp(const struct v4l2_format *f_sp,
498 struct v4l2_format *f_mp)
499{
500 struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
501 const struct v4l2_pix_format *pix = &f_sp->fmt.pix;
502
503 if (f_sp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
504 f_mp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
505 else if (f_sp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
506 f_mp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
507 else
508 return -EINVAL;
509
510 pix_mp->width = pix->width;
511 pix_mp->height = pix->height;
512 pix_mp->pixelformat = pix->pixelformat;
513 pix_mp->field = pix->field;
514 pix_mp->colorspace = pix->colorspace;
515 pix_mp->num_planes = 1;
516 pix_mp->plane_fmt[0].sizeimage = pix->sizeimage;
517 pix_mp->plane_fmt[0].bytesperline = pix->bytesperline;
518
519 return 0;
520}
521
522/**
523 * fmt_mp_to_sp() - Convert a multi-planar 1-plane format to its single-planar
524 * equivalent
525 */
526static int fmt_mp_to_sp(const struct v4l2_format *f_mp,
527 struct v4l2_format *f_sp)
528{
529 const struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
530 struct v4l2_pix_format *pix = &f_sp->fmt.pix;
531
532 if (f_mp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
533 f_sp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
534 else if (f_mp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
535 f_sp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
536 else
537 return -EINVAL;
538
539 pix->width = pix_mp->width;
540 pix->height = pix_mp->height;
541 pix->pixelformat = pix_mp->pixelformat;
542 pix->field = pix_mp->field;
543 pix->colorspace = pix_mp->colorspace;
544 pix->sizeimage = pix_mp->plane_fmt[0].sizeimage;
545 pix->bytesperline = pix_mp->plane_fmt[0].bytesperline;
546
547 return 0;
548}
549
Hans Verkuil069b7472008-12-30 07:04:34 -0300550static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300551 unsigned int cmd, void *arg)
552{
553 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300554 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300555 void *fh = file->private_data;
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300556 struct v4l2_fh *vfh = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300557 struct v4l2_format f_copy;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300558 int use_fh_prio = 0;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300559 long ret_prio = 0;
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300560 long ret = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300561
Hans Verkuil6a717882010-04-06 15:56:08 -0300562 if (ops == NULL) {
563 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
564 vfd->name);
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300565 return ret;
Hans Verkuil6a717882010-04-06 15:56:08 -0300566 }
567
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300568 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
569 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
570 v4l_print_ioctl(vfd->name, cmd);
571 printk(KERN_CONT "\n");
572 }
573
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300574 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300575 vfh = file->private_data;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300576 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
577 }
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300578
Hans Verkuil93d5a302011-08-09 09:32:06 -0300579 if (use_fh_prio)
580 ret_prio = v4l2_prio_check(vfd->prio, vfh->prio);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300581
Hans Verkuil6a717882010-04-06 15:56:08 -0300582 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300583
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300584 /* --- capabilities ------------------------------------------ */
585 case VIDIOC_QUERYCAP:
586 {
587 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300588
Hans Verkuila3998102008-07-21 02:57:38 -0300589 if (!ops->vidioc_querycap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300590 break;
591
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -0300592 cap->version = LINUX_VERSION_CODE;
Hans Verkuila3998102008-07-21 02:57:38 -0300593 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300594 if (!ret)
595 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
596 "version=0x%08x, "
597 "capabilities=0x%08x\n",
598 cap->driver, cap->card, cap->bus_info,
599 cap->version,
600 cap->capabilities);
601 break;
602 }
603
604 /* --- priority ------------------------------------------ */
605 case VIDIOC_G_PRIORITY:
606 {
607 enum v4l2_priority *p = arg;
608
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300609 if (ops->vidioc_g_priority) {
610 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300611 } else if (use_fh_prio) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300612 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
613 ret = 0;
614 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300615 if (!ret)
616 dbgarg(cmd, "priority is %d\n", *p);
617 break;
618 }
619 case VIDIOC_S_PRIORITY:
620 {
621 enum v4l2_priority *p = arg;
622
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300623 if (!ops->vidioc_s_priority && !use_fh_prio)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300624 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300625 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300626 if (ops->vidioc_s_priority)
627 ret = ops->vidioc_s_priority(file, fh, *p);
628 else
Hans Verkuil93d5a302011-08-09 09:32:06 -0300629 ret = ret_prio ? ret_prio :
630 v4l2_prio_change(&vfd->v4l2_dev->prio,
631 &vfh->prio, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300632 break;
633 }
634
635 /* --- capture ioctls ---------------------------------------- */
636 case VIDIOC_ENUM_FMT:
637 {
638 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300639
Trent Piepho19c96e42009-03-04 01:21:02 -0300640 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300641 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300642 if (likely(ops->vidioc_enum_fmt_vid_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300643 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300644 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300645 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300646 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300647 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
648 fh, f);
649 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300650 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300651 if (likely(ops->vidioc_enum_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300652 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300653 fh, f);
654 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300655 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300656 if (likely(ops->vidioc_enum_fmt_vid_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300657 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300658 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300659 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300660 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300661 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
662 fh, f);
663 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300664 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300665 if (likely(ops->vidioc_enum_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300666 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300667 fh, f);
668 break;
669 default:
670 break;
671 }
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300672 if (likely (!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300673 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
674 "pixelformat=%c%c%c%c, description='%s'\n",
675 f->index, f->type, f->flags,
676 (f->pixelformat & 0xff),
677 (f->pixelformat >> 8) & 0xff,
678 (f->pixelformat >> 16) & 0xff,
679 (f->pixelformat >> 24) & 0xff,
680 f->description);
Hans Verkuil93d5a302011-08-09 09:32:06 -0300681 else if (ret == -ENOTTY &&
682 (ops->vidioc_enum_fmt_vid_cap ||
683 ops->vidioc_enum_fmt_vid_out ||
684 ops->vidioc_enum_fmt_vid_cap_mplane ||
685 ops->vidioc_enum_fmt_vid_out_mplane ||
686 ops->vidioc_enum_fmt_vid_overlay ||
687 ops->vidioc_enum_fmt_type_private))
688 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300689 break;
690 }
691 case VIDIOC_G_FMT:
692 {
693 struct v4l2_format *f = (struct v4l2_format *)arg;
694
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300695 /* FIXME: Should be one dump per type */
696 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
697
698 switch (f->type) {
699 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300700 if (ops->vidioc_g_fmt_vid_cap) {
Hans Verkuila3998102008-07-21 02:57:38 -0300701 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300702 } else if (ops->vidioc_g_fmt_vid_cap_mplane) {
703 if (fmt_sp_to_mp(f, &f_copy))
704 break;
705 ret = ops->vidioc_g_fmt_vid_cap_mplane(file, fh,
706 &f_copy);
707 if (ret)
708 break;
709
710 /* Driver is currently in multi-planar format,
711 * we can't return it in single-planar API*/
712 if (f_copy.fmt.pix_mp.num_planes > 1) {
713 ret = -EBUSY;
714 break;
715 }
716
717 ret = fmt_mp_to_sp(&f_copy, f);
718 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300719 if (!ret)
720 v4l_print_pix_fmt(vfd, &f->fmt.pix);
721 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300722 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
723 if (ops->vidioc_g_fmt_vid_cap_mplane) {
724 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
725 fh, f);
726 } else if (ops->vidioc_g_fmt_vid_cap) {
727 if (fmt_mp_to_sp(f, &f_copy))
728 break;
729 ret = ops->vidioc_g_fmt_vid_cap(file,
730 fh, &f_copy);
731 if (ret)
732 break;
733
734 ret = fmt_sp_to_mp(&f_copy, f);
735 }
736 if (!ret)
737 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
738 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300739 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300740 if (likely(ops->vidioc_g_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300741 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300742 fh, f);
743 break;
744 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300745 if (ops->vidioc_g_fmt_vid_out) {
Hans Verkuila3998102008-07-21 02:57:38 -0300746 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300747 } else if (ops->vidioc_g_fmt_vid_out_mplane) {
748 if (fmt_sp_to_mp(f, &f_copy))
749 break;
750 ret = ops->vidioc_g_fmt_vid_out_mplane(file, fh,
751 &f_copy);
752 if (ret)
753 break;
754
755 /* Driver is currently in multi-planar format,
756 * we can't return it in single-planar API*/
757 if (f_copy.fmt.pix_mp.num_planes > 1) {
758 ret = -EBUSY;
759 break;
760 }
761
762 ret = fmt_mp_to_sp(&f_copy, f);
763 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300764 if (!ret)
765 v4l_print_pix_fmt(vfd, &f->fmt.pix);
766 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300767 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
768 if (ops->vidioc_g_fmt_vid_out_mplane) {
769 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
770 fh, f);
771 } else if (ops->vidioc_g_fmt_vid_out) {
772 if (fmt_mp_to_sp(f, &f_copy))
773 break;
774 ret = ops->vidioc_g_fmt_vid_out(file,
775 fh, &f_copy);
776 if (ret)
777 break;
778
779 ret = fmt_sp_to_mp(&f_copy, f);
780 }
781 if (!ret)
782 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
783 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300784 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300785 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300786 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300787 fh, f);
788 break;
789 case V4L2_BUF_TYPE_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300790 if (likely(ops->vidioc_g_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300791 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300792 break;
793 case V4L2_BUF_TYPE_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300794 if (likely(ops->vidioc_g_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300795 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300796 break;
797 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300798 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300799 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300800 fh, f);
801 break;
802 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300803 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300804 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300805 fh, f);
806 break;
807 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300808 if (likely(ops->vidioc_g_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300809 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300810 fh, f);
811 break;
812 }
Hans Verkuil93d5a302011-08-09 09:32:06 -0300813 if (unlikely(ret == -ENOTTY && have_fmt_ops(g)))
814 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300815
816 break;
817 }
818 case VIDIOC_S_FMT:
819 {
820 struct v4l2_format *f = (struct v4l2_format *)arg;
821
Hans Verkuil93d5a302011-08-09 09:32:06 -0300822 if (!have_fmt_ops(s))
823 break;
824 if (ret_prio) {
825 ret = ret_prio;
826 break;
827 }
828 ret = -EINVAL;
829
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300830 /* FIXME: Should be one dump per type */
831 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
832
833 switch (f->type) {
834 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300835 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300836 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300837 if (ops->vidioc_s_fmt_vid_cap) {
Hans Verkuila3998102008-07-21 02:57:38 -0300838 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300839 } else if (ops->vidioc_s_fmt_vid_cap_mplane) {
840 if (fmt_sp_to_mp(f, &f_copy))
841 break;
842 ret = ops->vidioc_s_fmt_vid_cap_mplane(file, fh,
843 &f_copy);
844 if (ret)
845 break;
846
847 if (f_copy.fmt.pix_mp.num_planes > 1) {
848 /* Drivers shouldn't adjust from 1-plane
849 * to more than 1-plane formats */
850 ret = -EBUSY;
851 WARN_ON(1);
852 break;
853 }
854
855 ret = fmt_mp_to_sp(&f_copy, f);
856 }
857 break;
858 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
859 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
860 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
861 if (ops->vidioc_s_fmt_vid_cap_mplane) {
862 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
863 fh, f);
864 } else if (ops->vidioc_s_fmt_vid_cap &&
865 f->fmt.pix_mp.num_planes == 1) {
866 if (fmt_mp_to_sp(f, &f_copy))
867 break;
868 ret = ops->vidioc_s_fmt_vid_cap(file,
869 fh, &f_copy);
870 if (ret)
871 break;
872
873 ret = fmt_sp_to_mp(&f_copy, f);
874 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300875 break;
876 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300877 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300878 if (ops->vidioc_s_fmt_vid_overlay)
879 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300880 fh, f);
881 break;
882 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300883 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300884 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300885 if (ops->vidioc_s_fmt_vid_out) {
Hans Verkuila3998102008-07-21 02:57:38 -0300886 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300887 } else if (ops->vidioc_s_fmt_vid_out_mplane) {
888 if (fmt_sp_to_mp(f, &f_copy))
889 break;
890 ret = ops->vidioc_s_fmt_vid_out_mplane(file, fh,
891 &f_copy);
892 if (ret)
893 break;
894
895 if (f_copy.fmt.pix_mp.num_planes > 1) {
896 /* Drivers shouldn't adjust from 1-plane
897 * to more than 1-plane formats */
898 ret = -EBUSY;
899 WARN_ON(1);
900 break;
901 }
902
903 ret = fmt_mp_to_sp(&f_copy, f);
904 }
905 break;
906 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
907 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
908 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
909 if (ops->vidioc_s_fmt_vid_out_mplane) {
910 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
911 fh, f);
912 } else if (ops->vidioc_s_fmt_vid_out &&
913 f->fmt.pix_mp.num_planes == 1) {
914 if (fmt_mp_to_sp(f, &f_copy))
915 break;
916 ret = ops->vidioc_s_fmt_vid_out(file,
917 fh, &f_copy);
918 if (ret)
919 break;
920
921 ret = fmt_mp_to_sp(&f_copy, f);
922 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300923 break;
924 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300925 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300926 if (ops->vidioc_s_fmt_vid_out_overlay)
927 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300928 fh, f);
929 break;
930 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300931 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300932 if (likely(ops->vidioc_s_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300933 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300934 break;
935 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300936 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300937 if (likely(ops->vidioc_s_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300938 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300939 break;
940 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300941 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300942 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300943 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300944 fh, f);
945 break;
946 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300947 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300948 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300949 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300950 fh, f);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300951
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300952 break;
953 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300954 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300955 if (likely(ops->vidioc_s_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300956 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300957 fh, f);
958 break;
959 }
960 break;
961 }
962 case VIDIOC_TRY_FMT:
963 {
964 struct v4l2_format *f = (struct v4l2_format *)arg;
965
966 /* FIXME: Should be one dump per type */
967 dbgarg(cmd, "type=%s\n", prt_names(f->type,
968 v4l2_type_names));
969 switch (f->type) {
970 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300971 CLEAR_AFTER_FIELD(f, fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300972 if (ops->vidioc_try_fmt_vid_cap) {
Hans Verkuila3998102008-07-21 02:57:38 -0300973 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300974 } else if (ops->vidioc_try_fmt_vid_cap_mplane) {
975 if (fmt_sp_to_mp(f, &f_copy))
976 break;
977 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
978 fh, &f_copy);
979 if (ret)
980 break;
981
982 if (f_copy.fmt.pix_mp.num_planes > 1) {
983 /* Drivers shouldn't adjust from 1-plane
984 * to more than 1-plane formats */
985 ret = -EBUSY;
986 WARN_ON(1);
987 break;
988 }
989 ret = fmt_mp_to_sp(&f_copy, f);
990 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300991 if (!ret)
992 v4l_print_pix_fmt(vfd, &f->fmt.pix);
993 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300994 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
995 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
996 if (ops->vidioc_try_fmt_vid_cap_mplane) {
997 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
998 fh, f);
999 } else if (ops->vidioc_try_fmt_vid_cap &&
1000 f->fmt.pix_mp.num_planes == 1) {
1001 if (fmt_mp_to_sp(f, &f_copy))
1002 break;
1003 ret = ops->vidioc_try_fmt_vid_cap(file,
1004 fh, &f_copy);
1005 if (ret)
1006 break;
1007
1008 ret = fmt_sp_to_mp(&f_copy, f);
1009 }
1010 if (!ret)
1011 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
1012 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001013 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001014 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001015 if (likely(ops->vidioc_try_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -03001016 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001017 fh, f);
1018 break;
1019 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001020 CLEAR_AFTER_FIELD(f, fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001021 if (ops->vidioc_try_fmt_vid_out) {
Hans Verkuila3998102008-07-21 02:57:38 -03001022 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001023 } else if (ops->vidioc_try_fmt_vid_out_mplane) {
1024 if (fmt_sp_to_mp(f, &f_copy))
1025 break;
1026 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
1027 fh, &f_copy);
1028 if (ret)
1029 break;
1030
1031 if (f_copy.fmt.pix_mp.num_planes > 1) {
1032 /* Drivers shouldn't adjust from 1-plane
1033 * to more than 1-plane formats */
1034 ret = -EBUSY;
1035 WARN_ON(1);
1036 break;
1037 }
1038 ret = fmt_mp_to_sp(&f_copy, f);
1039 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001040 if (!ret)
1041 v4l_print_pix_fmt(vfd, &f->fmt.pix);
1042 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001043 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1044 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
1045 if (ops->vidioc_try_fmt_vid_out_mplane) {
1046 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
1047 fh, f);
1048 } else if (ops->vidioc_try_fmt_vid_out &&
1049 f->fmt.pix_mp.num_planes == 1) {
1050 if (fmt_mp_to_sp(f, &f_copy))
1051 break;
1052 ret = ops->vidioc_try_fmt_vid_out(file,
1053 fh, &f_copy);
1054 if (ret)
1055 break;
1056
1057 ret = fmt_sp_to_mp(&f_copy, f);
1058 }
1059 if (!ret)
1060 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
1061 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001062 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001063 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001064 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -03001065 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001066 fh, f);
1067 break;
1068 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001069 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001070 if (likely(ops->vidioc_try_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -03001071 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001072 break;
1073 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001074 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001075 if (likely(ops->vidioc_try_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -03001076 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001077 break;
1078 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001079 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001080 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -03001081 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001082 fh, f);
1083 break;
1084 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001085 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001086 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -03001087 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001088 fh, f);
1089 break;
1090 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001091 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001092 if (likely(ops->vidioc_try_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -03001093 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001094 fh, f);
1095 break;
1096 }
Hans Verkuil93d5a302011-08-09 09:32:06 -03001097 if (unlikely(ret == -ENOTTY && have_fmt_ops(try)))
1098 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001099 break;
1100 }
1101 /* FIXME: Those buf reqs could be handled here,
1102 with some changes on videobuf to allow its header to be included at
1103 videodev2.h or being merged at videodev2.
1104 */
1105 case VIDIOC_REQBUFS:
1106 {
1107 struct v4l2_requestbuffers *p = arg;
1108
Hans Verkuila3998102008-07-21 02:57:38 -03001109 if (!ops->vidioc_reqbufs)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001110 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001111 if (ret_prio) {
1112 ret = ret_prio;
1113 break;
1114 }
Hans Verkuila3998102008-07-21 02:57:38 -03001115 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001116 if (ret)
1117 break;
1118
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001119 if (p->type < V4L2_BUF_TYPE_PRIVATE)
1120 CLEAR_AFTER_FIELD(p, memory);
1121
Hans Verkuila3998102008-07-21 02:57:38 -03001122 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001123 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
1124 p->count,
1125 prt_names(p->type, v4l2_type_names),
1126 prt_names(p->memory, v4l2_memory_names));
1127 break;
1128 }
1129 case VIDIOC_QUERYBUF:
1130 {
1131 struct v4l2_buffer *p = arg;
1132
Hans Verkuila3998102008-07-21 02:57:38 -03001133 if (!ops->vidioc_querybuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001134 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001135 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001136 if (ret)
1137 break;
1138
Hans Verkuila3998102008-07-21 02:57:38 -03001139 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001140 if (!ret)
1141 dbgbuf(cmd, vfd, p);
1142 break;
1143 }
1144 case VIDIOC_QBUF:
1145 {
1146 struct v4l2_buffer *p = arg;
1147
Hans Verkuila3998102008-07-21 02:57:38 -03001148 if (!ops->vidioc_qbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001149 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001150 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001151 if (ret)
1152 break;
1153
Hans Verkuila3998102008-07-21 02:57:38 -03001154 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001155 if (!ret)
1156 dbgbuf(cmd, vfd, p);
1157 break;
1158 }
1159 case VIDIOC_DQBUF:
1160 {
1161 struct v4l2_buffer *p = arg;
1162
Hans Verkuila3998102008-07-21 02:57:38 -03001163 if (!ops->vidioc_dqbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001164 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001165 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001166 if (ret)
1167 break;
1168
Hans Verkuila3998102008-07-21 02:57:38 -03001169 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001170 if (!ret)
1171 dbgbuf(cmd, vfd, p);
1172 break;
1173 }
1174 case VIDIOC_OVERLAY:
1175 {
1176 int *i = arg;
1177
Hans Verkuila3998102008-07-21 02:57:38 -03001178 if (!ops->vidioc_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001179 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001180 if (ret_prio) {
1181 ret = ret_prio;
1182 break;
1183 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001184 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001185 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001186 break;
1187 }
1188 case VIDIOC_G_FBUF:
1189 {
1190 struct v4l2_framebuffer *p = arg;
1191
Hans Verkuila3998102008-07-21 02:57:38 -03001192 if (!ops->vidioc_g_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001193 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001194 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001195 if (!ret) {
1196 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1197 p->capability, p->flags,
1198 (unsigned long)p->base);
1199 v4l_print_pix_fmt(vfd, &p->fmt);
1200 }
1201 break;
1202 }
1203 case VIDIOC_S_FBUF:
1204 {
1205 struct v4l2_framebuffer *p = arg;
1206
Hans Verkuila3998102008-07-21 02:57:38 -03001207 if (!ops->vidioc_s_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001208 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001209 if (ret_prio) {
1210 ret = ret_prio;
1211 break;
1212 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001213 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1214 p->capability, p->flags, (unsigned long)p->base);
1215 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -03001216 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001217 break;
1218 }
1219 case VIDIOC_STREAMON:
1220 {
1221 enum v4l2_buf_type i = *(int *)arg;
1222
Hans Verkuila3998102008-07-21 02:57:38 -03001223 if (!ops->vidioc_streamon)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001224 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001225 if (ret_prio) {
1226 ret = ret_prio;
1227 break;
1228 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001229 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001230 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001231 break;
1232 }
1233 case VIDIOC_STREAMOFF:
1234 {
1235 enum v4l2_buf_type i = *(int *)arg;
1236
Hans Verkuila3998102008-07-21 02:57:38 -03001237 if (!ops->vidioc_streamoff)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001238 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001239 if (ret_prio) {
1240 ret = ret_prio;
1241 break;
1242 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001243 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001244 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001245 break;
1246 }
1247 /* ---------- tv norms ---------- */
1248 case VIDIOC_ENUMSTD:
1249 {
1250 struct v4l2_standard *p = arg;
1251 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1252 unsigned int index = p->index, i, j = 0;
1253 const char *descr = "";
1254
Hans Verkuil93d5a302011-08-09 09:32:06 -03001255 if (id == 0)
1256 break;
1257 ret = -EINVAL;
1258
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001259 /* Return norm array in a canonical way */
1260 for (i = 0; i <= index && id; i++) {
1261 /* last std value in the standards array is 0, so this
1262 while always ends there since (id & 0) == 0. */
1263 while ((id & standards[j].std) != standards[j].std)
1264 j++;
1265 curr_id = standards[j].std;
1266 descr = standards[j].descr;
1267 j++;
1268 if (curr_id == 0)
1269 break;
1270 if (curr_id != V4L2_STD_PAL &&
1271 curr_id != V4L2_STD_SECAM &&
1272 curr_id != V4L2_STD_NTSC)
1273 id &= ~curr_id;
1274 }
1275 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001276 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001277
1278 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001279
1280 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1281 "framelines=%d\n", p->index,
1282 (unsigned long long)p->id, p->name,
1283 p->frameperiod.numerator,
1284 p->frameperiod.denominator,
1285 p->framelines);
1286
1287 ret = 0;
1288 break;
1289 }
1290 case VIDIOC_G_STD:
1291 {
1292 v4l2_std_id *id = arg;
1293
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001294 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001295 if (ops->vidioc_g_std)
1296 ret = ops->vidioc_g_std(file, fh, id);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001297 else if (vfd->current_norm) {
1298 ret = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001299 *id = vfd->current_norm;
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001300 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001301
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001302 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001303 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1304 break;
1305 }
1306 case VIDIOC_S_STD:
1307 {
1308 v4l2_std_id *id = arg, norm;
1309
1310 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1311
Hans Verkuil93d5a302011-08-09 09:32:06 -03001312 if (!ops->vidioc_s_std)
1313 break;
1314
1315 if (ret_prio) {
1316 ret = ret_prio;
1317 break;
1318 }
1319 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001320 norm = (*id) & vfd->tvnorms;
1321 if (vfd->tvnorms && !norm) /* Check if std is supported */
1322 break;
1323
1324 /* Calls the specific handler */
Hans Verkuil93d5a302011-08-09 09:32:06 -03001325 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001326
1327 /* Updates standard information */
1328 if (ret >= 0)
1329 vfd->current_norm = norm;
1330 break;
1331 }
1332 case VIDIOC_QUERYSTD:
1333 {
1334 v4l2_std_id *p = arg;
1335
Hans Verkuila3998102008-07-21 02:57:38 -03001336 if (!ops->vidioc_querystd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001337 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001338 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001339 if (!ret)
1340 dbgarg(cmd, "detected std=%08Lx\n",
1341 (unsigned long long)*p);
1342 break;
1343 }
1344 /* ------ input switching ---------- */
1345 /* FIXME: Inputs can be handled inside videodev2 */
1346 case VIDIOC_ENUMINPUT:
1347 {
1348 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001349
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001350 /*
1351 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1352 * CAP_STD here based on ioctl handler provided by the
1353 * driver. If the driver doesn't support these
1354 * for a specific input, it must override these flags.
1355 */
1356 if (ops->vidioc_s_std)
1357 p->capabilities |= V4L2_IN_CAP_STD;
1358 if (ops->vidioc_s_dv_preset)
1359 p->capabilities |= V4L2_IN_CAP_PRESETS;
1360 if (ops->vidioc_s_dv_timings)
1361 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1362
Hans Verkuila3998102008-07-21 02:57:38 -03001363 if (!ops->vidioc_enum_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001364 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001365
Hans Verkuila3998102008-07-21 02:57:38 -03001366 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001367 if (!ret)
1368 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1369 "audioset=%d, "
1370 "tuner=%d, std=%08Lx, status=%d\n",
1371 p->index, p->name, p->type, p->audioset,
1372 p->tuner,
1373 (unsigned long long)p->std,
1374 p->status);
1375 break;
1376 }
1377 case VIDIOC_G_INPUT:
1378 {
1379 unsigned int *i = arg;
1380
Hans Verkuila3998102008-07-21 02:57:38 -03001381 if (!ops->vidioc_g_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001382 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001383 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001384 if (!ret)
1385 dbgarg(cmd, "value=%d\n", *i);
1386 break;
1387 }
1388 case VIDIOC_S_INPUT:
1389 {
1390 unsigned int *i = arg;
1391
Hans Verkuila3998102008-07-21 02:57:38 -03001392 if (!ops->vidioc_s_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001393 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001394 if (ret_prio) {
1395 ret = ret_prio;
1396 break;
1397 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001398 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001399 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001400 break;
1401 }
1402
1403 /* ------ output switching ---------- */
1404 case VIDIOC_ENUMOUTPUT:
1405 {
1406 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001407
Hans Verkuila3998102008-07-21 02:57:38 -03001408 if (!ops->vidioc_enum_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001409 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001410
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001411 /*
1412 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1413 * CAP_STD here based on ioctl handler provided by the
1414 * driver. If the driver doesn't support these
1415 * for a specific output, it must override these flags.
1416 */
1417 if (ops->vidioc_s_std)
1418 p->capabilities |= V4L2_OUT_CAP_STD;
1419 if (ops->vidioc_s_dv_preset)
1420 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1421 if (ops->vidioc_s_dv_timings)
1422 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1423
Hans Verkuila3998102008-07-21 02:57:38 -03001424 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001425 if (!ret)
1426 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1427 "audioset=0x%x, "
1428 "modulator=%d, std=0x%08Lx\n",
1429 p->index, p->name, p->type, p->audioset,
1430 p->modulator, (unsigned long long)p->std);
1431 break;
1432 }
1433 case VIDIOC_G_OUTPUT:
1434 {
1435 unsigned int *i = arg;
1436
Hans Verkuila3998102008-07-21 02:57:38 -03001437 if (!ops->vidioc_g_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001438 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001439 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001440 if (!ret)
1441 dbgarg(cmd, "value=%d\n", *i);
1442 break;
1443 }
1444 case VIDIOC_S_OUTPUT:
1445 {
1446 unsigned int *i = arg;
1447
Hans Verkuila3998102008-07-21 02:57:38 -03001448 if (!ops->vidioc_s_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001449 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001450 if (ret_prio) {
1451 ret = ret_prio;
1452 break;
1453 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001454 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001455 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001456 break;
1457 }
1458
1459 /* --- controls ---------------------------------------------- */
1460 case VIDIOC_QUERYCTRL:
1461 {
1462 struct v4l2_queryctrl *p = arg;
1463
Hans Verkuil2d28b682011-03-12 08:54:43 -03001464 if (vfh && vfh->ctrl_handler)
1465 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1466 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001467 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1468 else if (ops->vidioc_queryctrl)
1469 ret = ops->vidioc_queryctrl(file, fh, p);
1470 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001471 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001472 if (!ret)
1473 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1474 "step=%d, default=%d, flags=0x%08x\n",
1475 p->id, p->type, p->name,
1476 p->minimum, p->maximum,
1477 p->step, p->default_value, p->flags);
1478 else
1479 dbgarg(cmd, "id=0x%x\n", p->id);
1480 break;
1481 }
1482 case VIDIOC_G_CTRL:
1483 {
1484 struct v4l2_control *p = arg;
1485
Hans Verkuil2d28b682011-03-12 08:54:43 -03001486 if (vfh && vfh->ctrl_handler)
1487 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1488 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001489 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1490 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001491 ret = ops->vidioc_g_ctrl(file, fh, p);
1492 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001493 struct v4l2_ext_controls ctrls;
1494 struct v4l2_ext_control ctrl;
1495
1496 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1497 ctrls.count = 1;
1498 ctrls.controls = &ctrl;
1499 ctrl.id = p->id;
1500 ctrl.value = p->value;
1501 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001502 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001503 if (ret == 0)
1504 p->value = ctrl.value;
1505 }
1506 } else
1507 break;
1508 if (!ret)
1509 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1510 else
1511 dbgarg(cmd, "id=0x%x\n", p->id);
1512 break;
1513 }
1514 case VIDIOC_S_CTRL:
1515 {
1516 struct v4l2_control *p = arg;
1517 struct v4l2_ext_controls ctrls;
1518 struct v4l2_ext_control ctrl;
1519
Hans Verkuil2d28b682011-03-12 08:54:43 -03001520 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001521 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001522 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001523 if (ret_prio) {
1524 ret = ret_prio;
1525 break;
1526 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001527
1528 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1529
Hans Verkuil2d28b682011-03-12 08:54:43 -03001530 if (vfh && vfh->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001531 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001532 break;
1533 }
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001534 if (vfd->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001535 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001536 break;
1537 }
Hans Verkuila3998102008-07-21 02:57:38 -03001538 if (ops->vidioc_s_ctrl) {
1539 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001540 break;
1541 }
Hans Verkuila3998102008-07-21 02:57:38 -03001542 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001543 break;
1544
1545 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1546 ctrls.count = 1;
1547 ctrls.controls = &ctrl;
1548 ctrl.id = p->id;
1549 ctrl.value = p->value;
1550 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001551 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001552 else
1553 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001554 break;
1555 }
1556 case VIDIOC_G_EXT_CTRLS:
1557 {
1558 struct v4l2_ext_controls *p = arg;
1559
1560 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001561 if (vfh && vfh->ctrl_handler)
1562 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1563 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001564 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001565 else if (ops->vidioc_g_ext_ctrls)
1566 ret = check_ext_ctrls(p, 0) ?
1567 ops->vidioc_g_ext_ctrls(file, fh, p) :
1568 -EINVAL;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001569 else
1570 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001571 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1572 break;
1573 }
1574 case VIDIOC_S_EXT_CTRLS:
1575 {
1576 struct v4l2_ext_controls *p = arg;
1577
1578 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001579 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1580 !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001581 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001582 if (ret_prio) {
1583 ret = ret_prio;
1584 break;
1585 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001586 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001587 if (vfh && vfh->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001588 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001589 else if (vfd->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001590 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001591 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001592 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001593 else
1594 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001595 break;
1596 }
1597 case VIDIOC_TRY_EXT_CTRLS:
1598 {
1599 struct v4l2_ext_controls *p = arg;
1600
1601 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001602 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1603 !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001604 break;
1605 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001606 if (vfh && vfh->ctrl_handler)
1607 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1608 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001609 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1610 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001611 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001612 else
1613 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001614 break;
1615 }
1616 case VIDIOC_QUERYMENU:
1617 {
1618 struct v4l2_querymenu *p = arg;
1619
Hans Verkuil2d28b682011-03-12 08:54:43 -03001620 if (vfh && vfh->ctrl_handler)
1621 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1622 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001623 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1624 else if (ops->vidioc_querymenu)
1625 ret = ops->vidioc_querymenu(file, fh, p);
1626 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001627 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001628 if (!ret)
1629 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1630 p->id, p->index, p->name);
1631 else
1632 dbgarg(cmd, "id=0x%x, index=%d\n",
1633 p->id, p->index);
1634 break;
1635 }
1636 /* --- audio ---------------------------------------------- */
1637 case VIDIOC_ENUMAUDIO:
1638 {
1639 struct v4l2_audio *p = arg;
1640
Hans Verkuila3998102008-07-21 02:57:38 -03001641 if (!ops->vidioc_enumaudio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001642 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001643 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001644 if (!ret)
1645 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1646 "mode=0x%x\n", p->index, p->name,
1647 p->capability, p->mode);
1648 else
1649 dbgarg(cmd, "index=%d\n", p->index);
1650 break;
1651 }
1652 case VIDIOC_G_AUDIO:
1653 {
1654 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001655
Hans Verkuila3998102008-07-21 02:57:38 -03001656 if (!ops->vidioc_g_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001657 break;
1658
Hans Verkuila3998102008-07-21 02:57:38 -03001659 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001660 if (!ret)
1661 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1662 "mode=0x%x\n", p->index,
1663 p->name, p->capability, p->mode);
1664 else
1665 dbgarg(cmd, "index=%d\n", p->index);
1666 break;
1667 }
1668 case VIDIOC_S_AUDIO:
1669 {
1670 struct v4l2_audio *p = arg;
1671
Hans Verkuila3998102008-07-21 02:57:38 -03001672 if (!ops->vidioc_s_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001673 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001674 if (ret_prio) {
1675 ret = ret_prio;
1676 break;
1677 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001678 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1679 "mode=0x%x\n", p->index, p->name,
1680 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001681 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001682 break;
1683 }
1684 case VIDIOC_ENUMAUDOUT:
1685 {
1686 struct v4l2_audioout *p = arg;
1687
Hans Verkuila3998102008-07-21 02:57:38 -03001688 if (!ops->vidioc_enumaudout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001689 break;
1690 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001691 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001692 if (!ret)
1693 dbgarg2("index=%d, name=%s, capability=%d, "
1694 "mode=%d\n", p->index, p->name,
1695 p->capability, p->mode);
1696 break;
1697 }
1698 case VIDIOC_G_AUDOUT:
1699 {
1700 struct v4l2_audioout *p = arg;
1701
Hans Verkuila3998102008-07-21 02:57:38 -03001702 if (!ops->vidioc_g_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001703 break;
Trent Piepho337f9d22009-03-04 01:21:02 -03001704
Hans Verkuila3998102008-07-21 02:57:38 -03001705 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001706 if (!ret)
1707 dbgarg2("index=%d, name=%s, capability=%d, "
1708 "mode=%d\n", p->index, p->name,
1709 p->capability, p->mode);
1710 break;
1711 }
1712 case VIDIOC_S_AUDOUT:
1713 {
1714 struct v4l2_audioout *p = arg;
1715
Hans Verkuila3998102008-07-21 02:57:38 -03001716 if (!ops->vidioc_s_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001717 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001718 if (ret_prio) {
1719 ret = ret_prio;
1720 break;
1721 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001722 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1723 "mode=%d\n", p->index, p->name,
1724 p->capability, p->mode);
1725
Hans Verkuila3998102008-07-21 02:57:38 -03001726 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001727 break;
1728 }
1729 case VIDIOC_G_MODULATOR:
1730 {
1731 struct v4l2_modulator *p = arg;
1732
Hans Verkuila3998102008-07-21 02:57:38 -03001733 if (!ops->vidioc_g_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001734 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001735 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001736 if (!ret)
1737 dbgarg(cmd, "index=%d, name=%s, "
1738 "capability=%d, rangelow=%d,"
1739 " rangehigh=%d, txsubchans=%d\n",
1740 p->index, p->name, p->capability,
1741 p->rangelow, p->rangehigh,
1742 p->txsubchans);
1743 break;
1744 }
1745 case VIDIOC_S_MODULATOR:
1746 {
1747 struct v4l2_modulator *p = arg;
1748
Hans Verkuila3998102008-07-21 02:57:38 -03001749 if (!ops->vidioc_s_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001750 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001751 if (ret_prio) {
1752 ret = ret_prio;
1753 break;
1754 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001755 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1756 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1757 p->index, p->name, p->capability, p->rangelow,
1758 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001759 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001760 break;
1761 }
1762 case VIDIOC_G_CROP:
1763 {
1764 struct v4l2_crop *p = arg;
1765
Hans Verkuila3998102008-07-21 02:57:38 -03001766 if (!ops->vidioc_g_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001767 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001768
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001769 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001770 ret = ops->vidioc_g_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001771 if (!ret)
1772 dbgrect(vfd, "", &p->c);
1773 break;
1774 }
1775 case VIDIOC_S_CROP:
1776 {
1777 struct v4l2_crop *p = arg;
1778
Hans Verkuila3998102008-07-21 02:57:38 -03001779 if (!ops->vidioc_s_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001780 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001781 if (ret_prio) {
1782 ret = ret_prio;
1783 break;
1784 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001785 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1786 dbgrect(vfd, "", &p->c);
Hans Verkuila3998102008-07-21 02:57:38 -03001787 ret = ops->vidioc_s_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001788 break;
1789 }
1790 case VIDIOC_CROPCAP:
1791 {
1792 struct v4l2_cropcap *p = arg;
1793
1794 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuila3998102008-07-21 02:57:38 -03001795 if (!ops->vidioc_cropcap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001796 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001797
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001798 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001799 ret = ops->vidioc_cropcap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001800 if (!ret) {
1801 dbgrect(vfd, "bounds ", &p->bounds);
1802 dbgrect(vfd, "defrect ", &p->defrect);
1803 }
1804 break;
1805 }
1806 case VIDIOC_G_JPEGCOMP:
1807 {
1808 struct v4l2_jpegcompression *p = arg;
1809
Hans Verkuila3998102008-07-21 02:57:38 -03001810 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001811 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001812
Hans Verkuila3998102008-07-21 02:57:38 -03001813 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001814 if (!ret)
1815 dbgarg(cmd, "quality=%d, APPn=%d, "
1816 "APP_len=%d, COM_len=%d, "
1817 "jpeg_markers=%d\n",
1818 p->quality, p->APPn, p->APP_len,
1819 p->COM_len, p->jpeg_markers);
1820 break;
1821 }
1822 case VIDIOC_S_JPEGCOMP:
1823 {
1824 struct v4l2_jpegcompression *p = arg;
1825
Hans Verkuila3998102008-07-21 02:57:38 -03001826 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001827 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001828 if (ret_prio) {
1829 ret = ret_prio;
1830 break;
1831 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001832 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1833 "COM_len=%d, jpeg_markers=%d\n",
1834 p->quality, p->APPn, p->APP_len,
1835 p->COM_len, p->jpeg_markers);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001836 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001837 break;
1838 }
1839 case VIDIOC_G_ENC_INDEX:
1840 {
1841 struct v4l2_enc_idx *p = arg;
1842
Hans Verkuila3998102008-07-21 02:57:38 -03001843 if (!ops->vidioc_g_enc_index)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001844 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001845 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001846 if (!ret)
1847 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1848 p->entries, p->entries_cap);
1849 break;
1850 }
1851 case VIDIOC_ENCODER_CMD:
1852 {
1853 struct v4l2_encoder_cmd *p = arg;
1854
Hans Verkuila3998102008-07-21 02:57:38 -03001855 if (!ops->vidioc_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001856 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001857 if (ret_prio) {
1858 ret = ret_prio;
1859 break;
1860 }
Hans Verkuila3998102008-07-21 02:57:38 -03001861 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001862 if (!ret)
1863 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1864 break;
1865 }
1866 case VIDIOC_TRY_ENCODER_CMD:
1867 {
1868 struct v4l2_encoder_cmd *p = arg;
1869
Hans Verkuila3998102008-07-21 02:57:38 -03001870 if (!ops->vidioc_try_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001871 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001872 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001873 if (!ret)
1874 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1875 break;
1876 }
1877 case VIDIOC_G_PARM:
1878 {
1879 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001880
Hans Verkuil93d5a302011-08-09 09:32:06 -03001881 if (!ops->vidioc_g_parm && !vfd->current_norm)
1882 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001883 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001884 ret = check_fmt(ops, p->type);
1885 if (ret)
1886 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001887 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001888 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001889 v4l2_std_id std = vfd->current_norm;
1890
Hans Verkuil93d5a302011-08-09 09:32:06 -03001891 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001892 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001893 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001894
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001895 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001896 if (ops->vidioc_g_std)
1897 ret = ops->vidioc_g_std(file, fh, &std);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001898 if (ret == 0)
1899 v4l2_video_std_frame_period(std,
1900 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001901 }
1902
1903 dbgarg(cmd, "type=%d\n", p->type);
1904 break;
1905 }
1906 case VIDIOC_S_PARM:
1907 {
1908 struct v4l2_streamparm *p = arg;
1909
Hans Verkuila3998102008-07-21 02:57:38 -03001910 if (!ops->vidioc_s_parm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001911 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001912 if (ret_prio) {
1913 ret = ret_prio;
1914 break;
1915 }
Trent Piepho34796bc2009-03-28 22:25:35 -03001916 ret = check_fmt(ops, p->type);
1917 if (ret)
1918 break;
1919
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001920 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001921 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001922 break;
1923 }
1924 case VIDIOC_G_TUNER:
1925 {
1926 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001927
Hans Verkuila3998102008-07-21 02:57:38 -03001928 if (!ops->vidioc_g_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001929 break;
1930
Hans Verkuil227690d2011-06-12 06:36:41 -03001931 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1932 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001933 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001934 if (!ret)
1935 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1936 "capability=0x%x, rangelow=%d, "
1937 "rangehigh=%d, signal=%d, afc=%d, "
1938 "rxsubchans=0x%x, audmode=%d\n",
1939 p->index, p->name, p->type,
1940 p->capability, p->rangelow,
1941 p->rangehigh, p->signal, p->afc,
1942 p->rxsubchans, p->audmode);
1943 break;
1944 }
1945 case VIDIOC_S_TUNER:
1946 {
1947 struct v4l2_tuner *p = arg;
1948
Hans Verkuila3998102008-07-21 02:57:38 -03001949 if (!ops->vidioc_s_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001950 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001951 if (ret_prio) {
1952 ret = ret_prio;
1953 break;
1954 }
Hans Verkuil227690d2011-06-12 06:36:41 -03001955 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1956 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001957 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1958 "capability=0x%x, rangelow=%d, "
1959 "rangehigh=%d, signal=%d, afc=%d, "
1960 "rxsubchans=0x%x, audmode=%d\n",
1961 p->index, p->name, p->type,
1962 p->capability, p->rangelow,
1963 p->rangehigh, p->signal, p->afc,
1964 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001965 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001966 break;
1967 }
1968 case VIDIOC_G_FREQUENCY:
1969 {
1970 struct v4l2_frequency *p = arg;
1971
Hans Verkuila3998102008-07-21 02:57:38 -03001972 if (!ops->vidioc_g_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001973 break;
1974
Hans Verkuil227690d2011-06-12 06:36:41 -03001975 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1976 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001977 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001978 if (!ret)
1979 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1980 p->tuner, p->type, p->frequency);
1981 break;
1982 }
1983 case VIDIOC_S_FREQUENCY:
1984 {
1985 struct v4l2_frequency *p = arg;
1986
Hans Verkuila3998102008-07-21 02:57:38 -03001987 if (!ops->vidioc_s_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001988 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001989 if (ret_prio) {
1990 ret = ret_prio;
1991 break;
1992 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001993 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1994 p->tuner, p->type, p->frequency);
Hans Verkuila3998102008-07-21 02:57:38 -03001995 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001996 break;
1997 }
1998 case VIDIOC_G_SLICED_VBI_CAP:
1999 {
2000 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002001
Hans Verkuila3998102008-07-21 02:57:38 -03002002 if (!ops->vidioc_g_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002003 break;
Trent Piepho19c96e42009-03-04 01:21:02 -03002004
2005 /* Clear up to type, everything after type is zerod already */
2006 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
2007
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002008 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03002009 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002010 if (!ret)
2011 dbgarg2("service_set=%d\n", p->service_set);
2012 break;
2013 }
2014 case VIDIOC_LOG_STATUS:
2015 {
Hans Verkuila3998102008-07-21 02:57:38 -03002016 if (!ops->vidioc_log_status)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002017 break;
Hans Verkuila3998102008-07-21 02:57:38 -03002018 ret = ops->vidioc_log_status(file, fh);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002019 break;
2020 }
2021#ifdef CONFIG_VIDEO_ADV_DEBUG
2022 case VIDIOC_DBG_G_REGISTER:
2023 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03002024 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002025
Hans Verkuila1198cc2011-01-08 09:53:32 -03002026 if (ops->vidioc_g_register) {
2027 if (!capable(CAP_SYS_ADMIN))
2028 ret = -EPERM;
2029 else
2030 ret = ops->vidioc_g_register(file, fh, p);
2031 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002032 break;
2033 }
2034 case VIDIOC_DBG_S_REGISTER:
2035 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03002036 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002037
Hans Verkuila1198cc2011-01-08 09:53:32 -03002038 if (ops->vidioc_s_register) {
2039 if (!capable(CAP_SYS_ADMIN))
2040 ret = -EPERM;
2041 else
2042 ret = ops->vidioc_s_register(file, fh, p);
2043 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002044 break;
2045 }
2046#endif
Hans Verkuilaecde8b2008-12-30 07:14:19 -03002047 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002048 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03002049 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002050
Hans Verkuila3998102008-07-21 02:57:38 -03002051 if (!ops->vidioc_g_chip_ident)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002052 break;
Hans Verkuil80b36e02009-02-07 11:00:02 -03002053 p->ident = V4L2_IDENT_NONE;
2054 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03002055 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002056 if (!ret)
2057 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
2058 break;
2059 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002060 case VIDIOC_S_HW_FREQ_SEEK:
2061 {
2062 struct v4l2_hw_freq_seek *p = arg;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03002063 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002064
Hans Verkuila3998102008-07-21 02:57:38 -03002065 if (!ops->vidioc_s_hw_freq_seek)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002066 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002067 if (ret_prio) {
2068 ret = ret_prio;
2069 break;
2070 }
Hans Verkuila6cf90a2011-06-14 04:03:26 -03002071 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
2072 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002073 dbgarg(cmd,
Hans Verkuila6cf90a2011-06-14 04:03:26 -03002074 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
2075 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
2076 if (p->type != type)
2077 ret = -EINVAL;
2078 else
2079 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
Hans Verkuila3998102008-07-21 02:57:38 -03002080 break;
2081 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002082 case VIDIOC_ENUM_FRAMESIZES:
2083 {
2084 struct v4l2_frmsizeenum *p = arg;
2085
2086 if (!ops->vidioc_enum_framesizes)
2087 break;
2088
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002089 ret = ops->vidioc_enum_framesizes(file, fh, p);
2090 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03002091 "index=%d, pixelformat=%c%c%c%c, type=%d ",
2092 p->index,
2093 (p->pixel_format & 0xff),
2094 (p->pixel_format >> 8) & 0xff,
2095 (p->pixel_format >> 16) & 0xff,
2096 (p->pixel_format >> 24) & 0xff,
2097 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002098 switch (p->type) {
2099 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002100 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002101 p->discrete.width, p->discrete.height);
2102 break;
2103 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002104 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002105 p->stepwise.min_width, p->stepwise.min_height,
2106 p->stepwise.step_width, p->stepwise.step_height,
2107 p->stepwise.max_width, p->stepwise.max_height);
2108 break;
2109 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002110 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002111 break;
2112 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002113 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002114 }
2115
2116 break;
2117 }
2118 case VIDIOC_ENUM_FRAMEINTERVALS:
2119 {
2120 struct v4l2_frmivalenum *p = arg;
2121
2122 if (!ops->vidioc_enum_frameintervals)
2123 break;
2124
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002125 ret = ops->vidioc_enum_frameintervals(file, fh, p);
2126 dbgarg(cmd,
2127 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
2128 p->index, p->pixel_format,
2129 p->width, p->height, p->type);
2130 switch (p->type) {
2131 case V4L2_FRMIVAL_TYPE_DISCRETE:
2132 dbgarg2("fps=%d/%d\n",
2133 p->discrete.numerator,
2134 p->discrete.denominator);
2135 break;
2136 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03002137 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
2138 p->stepwise.min.numerator,
2139 p->stepwise.min.denominator,
2140 p->stepwise.max.numerator,
2141 p->stepwise.max.denominator,
2142 p->stepwise.step.numerator,
2143 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002144 break;
2145 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
2146 dbgarg2("continuous\n");
2147 break;
2148 default:
2149 dbgarg2("- Unknown type!\n");
2150 }
2151 break;
2152 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002153 case VIDIOC_ENUM_DV_PRESETS:
2154 {
2155 struct v4l2_dv_enum_preset *p = arg;
2156
2157 if (!ops->vidioc_enum_dv_presets)
2158 break;
2159
2160 ret = ops->vidioc_enum_dv_presets(file, fh, p);
2161 if (!ret)
2162 dbgarg(cmd,
2163 "index=%d, preset=%d, name=%s, width=%d,"
2164 " height=%d ",
2165 p->index, p->preset, p->name, p->width,
2166 p->height);
2167 break;
2168 }
2169 case VIDIOC_S_DV_PRESET:
2170 {
2171 struct v4l2_dv_preset *p = arg;
2172
2173 if (!ops->vidioc_s_dv_preset)
2174 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002175 if (ret_prio) {
2176 ret = ret_prio;
2177 break;
2178 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002179
2180 dbgarg(cmd, "preset=%d\n", p->preset);
2181 ret = ops->vidioc_s_dv_preset(file, fh, p);
2182 break;
2183 }
2184 case VIDIOC_G_DV_PRESET:
2185 {
2186 struct v4l2_dv_preset *p = arg;
2187
2188 if (!ops->vidioc_g_dv_preset)
2189 break;
2190
2191 ret = ops->vidioc_g_dv_preset(file, fh, p);
2192 if (!ret)
2193 dbgarg(cmd, "preset=%d\n", p->preset);
2194 break;
2195 }
2196 case VIDIOC_QUERY_DV_PRESET:
2197 {
2198 struct v4l2_dv_preset *p = arg;
2199
2200 if (!ops->vidioc_query_dv_preset)
2201 break;
2202
2203 ret = ops->vidioc_query_dv_preset(file, fh, p);
2204 if (!ret)
2205 dbgarg(cmd, "preset=%d\n", p->preset);
2206 break;
2207 }
2208 case VIDIOC_S_DV_TIMINGS:
2209 {
2210 struct v4l2_dv_timings *p = arg;
2211
2212 if (!ops->vidioc_s_dv_timings)
2213 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002214 if (ret_prio) {
2215 ret = ret_prio;
2216 break;
2217 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002218
2219 switch (p->type) {
2220 case V4L2_DV_BT_656_1120:
2221 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2222 " width=%d, height=%d, polarities=%x,"
2223 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2224 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2225 " il_vfrontporch=%d, il_vsync=%d,"
2226 " il_vbackporch=%d\n",
2227 p->bt.interlaced, p->bt.pixelclock,
2228 p->bt.width, p->bt.height, p->bt.polarities,
2229 p->bt.hfrontporch, p->bt.hsync,
2230 p->bt.hbackporch, p->bt.vfrontporch,
2231 p->bt.vsync, p->bt.vbackporch,
2232 p->bt.il_vfrontporch, p->bt.il_vsync,
2233 p->bt.il_vbackporch);
2234 ret = ops->vidioc_s_dv_timings(file, fh, p);
2235 break;
2236 default:
2237 dbgarg2("Unknown type %d!\n", p->type);
2238 break;
2239 }
2240 break;
2241 }
2242 case VIDIOC_G_DV_TIMINGS:
2243 {
2244 struct v4l2_dv_timings *p = arg;
2245
2246 if (!ops->vidioc_g_dv_timings)
2247 break;
2248
2249 ret = ops->vidioc_g_dv_timings(file, fh, p);
2250 if (!ret) {
2251 switch (p->type) {
2252 case V4L2_DV_BT_656_1120:
2253 dbgarg2("bt-656/1120:interlaced=%d,"
2254 " pixelclock=%lld,"
2255 " width=%d, height=%d, polarities=%x,"
2256 " hfrontporch=%d, hsync=%d,"
2257 " hbackporch=%d, vfrontporch=%d,"
2258 " vsync=%d, vbackporch=%d,"
2259 " il_vfrontporch=%d, il_vsync=%d,"
2260 " il_vbackporch=%d\n",
2261 p->bt.interlaced, p->bt.pixelclock,
2262 p->bt.width, p->bt.height,
2263 p->bt.polarities, p->bt.hfrontporch,
2264 p->bt.hsync, p->bt.hbackporch,
2265 p->bt.vfrontporch, p->bt.vsync,
2266 p->bt.vbackporch, p->bt.il_vfrontporch,
2267 p->bt.il_vsync, p->bt.il_vbackporch);
2268 break;
2269 default:
2270 dbgarg2("Unknown type %d!\n", p->type);
2271 break;
2272 }
2273 }
2274 break;
2275 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002276 case VIDIOC_DQEVENT:
2277 {
2278 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002279
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002280 if (!ops->vidioc_subscribe_event)
2281 break;
2282
2283 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2284 if (ret < 0) {
2285 dbgarg(cmd, "no pending events?");
2286 break;
2287 }
2288 dbgarg(cmd,
2289 "pending=%d, type=0x%8.8x, sequence=%d, "
2290 "timestamp=%lu.%9.9lu ",
2291 ev->pending, ev->type, ev->sequence,
2292 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2293 break;
2294 }
2295 case VIDIOC_SUBSCRIBE_EVENT:
2296 {
2297 struct v4l2_event_subscription *sub = arg;
2298
2299 if (!ops->vidioc_subscribe_event)
2300 break;
2301
2302 ret = ops->vidioc_subscribe_event(fh, sub);
2303 if (ret < 0) {
2304 dbgarg(cmd, "failed, ret=%ld", ret);
2305 break;
2306 }
2307 dbgarg(cmd, "type=0x%8.8x", sub->type);
2308 break;
2309 }
2310 case VIDIOC_UNSUBSCRIBE_EVENT:
2311 {
2312 struct v4l2_event_subscription *sub = arg;
2313
2314 if (!ops->vidioc_unsubscribe_event)
2315 break;
2316
2317 ret = ops->vidioc_unsubscribe_event(fh, sub);
2318 if (ret < 0) {
2319 dbgarg(cmd, "failed, ret=%ld", ret);
2320 break;
2321 }
2322 dbgarg(cmd, "type=0x%8.8x", sub->type);
2323 break;
2324 }
Hans Verkuila3998102008-07-21 02:57:38 -03002325 default:
Hans Verkuila3998102008-07-21 02:57:38 -03002326 if (!ops->vidioc_default)
2327 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002328 ret = ops->vidioc_default(file, fh, ret_prio >= 0, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002329 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002330 } /* switch */
2331
2332 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2333 if (ret < 0) {
2334 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002335 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002336 }
2337 }
2338
2339 return ret;
2340}
2341
Trent Piepho19c96e42009-03-04 01:21:02 -03002342/* In some cases, only a few fields are used as input, i.e. when the app sets
2343 * "index" and then the driver fills in the rest of the structure for the thing
2344 * with that index. We only need to copy up the first non-input field. */
2345static unsigned long cmd_input_size(unsigned int cmd)
2346{
2347 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002348#define CMDINSIZE(cmd, type, field) \
2349 case VIDIOC_##cmd: \
2350 return offsetof(struct v4l2_##type, field) + \
2351 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002352
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002353 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002354 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2355 CMDINSIZE(G_FMT, format, type);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002356 CMDINSIZE(QUERYBUF, buffer, length);
Trent Piepho19c96e42009-03-04 01:21:02 -03002357 CMDINSIZE(G_PARM, streamparm, type);
2358 CMDINSIZE(ENUMSTD, standard, index);
2359 CMDINSIZE(ENUMINPUT, input, index);
2360 CMDINSIZE(G_CTRL, control, id);
2361 CMDINSIZE(G_TUNER, tuner, index);
2362 CMDINSIZE(QUERYCTRL, queryctrl, id);
2363 CMDINSIZE(QUERYMENU, querymenu, index);
2364 CMDINSIZE(ENUMOUTPUT, output, index);
2365 CMDINSIZE(G_MODULATOR, modulator, index);
2366 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2367 CMDINSIZE(CROPCAP, cropcap, type);
2368 CMDINSIZE(G_CROP, crop, type);
2369 CMDINSIZE(ENUMAUDIO, audio, index);
2370 CMDINSIZE(ENUMAUDOUT, audioout, index);
2371 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2372 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2373 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2374 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2375 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2376 default:
2377 return _IOC_SIZE(cmd);
2378 }
2379}
2380
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002381static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2382 void * __user *user_ptr, void ***kernel_ptr)
2383{
2384 int ret = 0;
2385
2386 switch (cmd) {
2387 case VIDIOC_QUERYBUF:
2388 case VIDIOC_QBUF:
2389 case VIDIOC_DQBUF: {
2390 struct v4l2_buffer *buf = parg;
2391
2392 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2393 if (buf->length > VIDEO_MAX_PLANES) {
2394 ret = -EINVAL;
2395 break;
2396 }
2397 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002398 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002399 *array_size = sizeof(struct v4l2_plane) * buf->length;
2400 ret = 1;
2401 }
2402 break;
2403 }
2404
2405 case VIDIOC_S_EXT_CTRLS:
2406 case VIDIOC_G_EXT_CTRLS:
2407 case VIDIOC_TRY_EXT_CTRLS: {
2408 struct v4l2_ext_controls *ctrls = parg;
2409
2410 if (ctrls->count != 0) {
2411 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002412 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002413 *array_size = sizeof(struct v4l2_ext_control)
2414 * ctrls->count;
2415 ret = 1;
2416 }
2417 break;
2418 }
2419 }
2420
2421 return ret;
2422}
2423
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002424long
2425video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2426 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002427{
2428 char sbuf[128];
2429 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002430 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002431 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002432 bool has_array_args;
2433 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002434 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002435 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002436
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002437 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002438 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002439 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2440 parg = sbuf;
2441 } else {
2442 /* too big to allocate from stack */
2443 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2444 if (NULL == mbuf)
2445 return -ENOMEM;
2446 parg = mbuf;
2447 }
2448
2449 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002450 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2451 unsigned long n = cmd_input_size(cmd);
2452
2453 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002454 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002455
2456 /* zero out anything we don't copy from userspace */
2457 if (n < _IOC_SIZE(cmd))
2458 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002459 } else {
2460 /* read-only ioctl */
2461 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002462 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002463 }
2464
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002465 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2466 if (err < 0)
2467 goto out;
2468 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002469
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002470 if (has_array_args) {
2471 /*
2472 * When adding new types of array args, make sure that the
2473 * parent argument to ioctl (which contains the pointer to the
2474 * array) fits into sbuf (so that mbuf will still remain
2475 * unused up to here).
2476 */
2477 mbuf = kmalloc(array_size, GFP_KERNEL);
2478 err = -ENOMEM;
2479 if (NULL == mbuf)
2480 goto out_array_args;
2481 err = -EFAULT;
2482 if (copy_from_user(mbuf, user_ptr, array_size))
2483 goto out_array_args;
2484 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002485 }
2486
2487 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002488 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002489 if (err == -ENOIOCTLCMD)
2490 err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002491
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002492 if (has_array_args) {
2493 *kernel_ptr = user_ptr;
2494 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002495 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002496 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002497 }
2498 if (err < 0)
2499 goto out;
2500
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002501out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002502 /* Copy results into user buffer */
2503 switch (_IOC_DIR(cmd)) {
2504 case _IOC_READ:
2505 case (_IOC_WRITE | _IOC_READ):
2506 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2507 err = -EFAULT;
2508 break;
2509 }
2510
2511out:
2512 kfree(mbuf);
2513 return err;
2514}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002515EXPORT_SYMBOL(video_usercopy);
2516
2517long video_ioctl2(struct file *file,
2518 unsigned int cmd, unsigned long arg)
2519{
2520 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2521}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002522EXPORT_SYMBOL(video_ioctl2);