blob: 91be4e871f43644c2052c942092a3f808688c9a8 [file] [log] [blame]
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic framework to process V4L2 ioctl commands.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
Alan Coxd9b01442008-10-27 15:13:47 -030011 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
Hans Verkuil35ea11f2008-07-20 08:12:02 -030012 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
13 */
14
15#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030017#include <linux/types.h>
18#include <linux/kernel.h>
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -030019#include <linux/version.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030020
Hans Verkuil35ea11f2008-07-20 08:12:02 -030021#include <linux/videodev2.h>
22
Hans Verkuil35ea11f2008-07-20 08:12:02 -030023#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
Hans Verkuil11bbc1c2010-05-16 09:24:06 -030025#include <media/v4l2-ctrls.h>
Sakari Ailusd3d7c962010-03-27 11:02:10 -030026#include <media/v4l2-fh.h>
27#include <media/v4l2-event.h>
Hans Verkuil99cd47bc2011-03-11 19:00:56 -030028#include <media/v4l2-device.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030029#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030
31#define dbgarg(cmd, fmt, arg...) \
32 do { \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
37 } \
38 } while (0)
39
40#define dbgarg2(fmt, arg...) \
41 do { \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
44 } while (0)
45
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030046#define dbgarg3(fmt, arg...) \
47 do { \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
50 } while (0)
51
Lucas De Marchi25985ed2011-03-30 22:57:33 -030052/* Zero out the end of the struct pointed to by p. Everything after, but
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030053 * not including, the specified field is cleared. */
54#define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
57
Hans Verkuil35ea11f2008-07-20 08:12:02 -030058struct std_descr {
59 v4l2_std_id std;
60 const char *descr;
61};
62
63static const struct std_descr standards[] = {
64 { V4L2_STD_NTSC, "NTSC" },
65 { V4L2_STD_NTSC_M, "NTSC-M" },
66 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
67 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
68 { V4L2_STD_NTSC_443, "NTSC-443" },
69 { V4L2_STD_PAL, "PAL" },
70 { V4L2_STD_PAL_BG, "PAL-BG" },
71 { V4L2_STD_PAL_B, "PAL-B" },
72 { V4L2_STD_PAL_B1, "PAL-B1" },
73 { V4L2_STD_PAL_G, "PAL-G" },
74 { V4L2_STD_PAL_H, "PAL-H" },
75 { V4L2_STD_PAL_I, "PAL-I" },
76 { V4L2_STD_PAL_DK, "PAL-DK" },
77 { V4L2_STD_PAL_D, "PAL-D" },
78 { V4L2_STD_PAL_D1, "PAL-D1" },
79 { V4L2_STD_PAL_K, "PAL-K" },
80 { V4L2_STD_PAL_M, "PAL-M" },
81 { V4L2_STD_PAL_N, "PAL-N" },
82 { V4L2_STD_PAL_Nc, "PAL-Nc" },
83 { V4L2_STD_PAL_60, "PAL-60" },
84 { V4L2_STD_SECAM, "SECAM" },
85 { V4L2_STD_SECAM_B, "SECAM-B" },
86 { V4L2_STD_SECAM_G, "SECAM-G" },
87 { V4L2_STD_SECAM_H, "SECAM-H" },
88 { V4L2_STD_SECAM_DK, "SECAM-DK" },
89 { V4L2_STD_SECAM_D, "SECAM-D" },
90 { V4L2_STD_SECAM_K, "SECAM-K" },
91 { V4L2_STD_SECAM_K1, "SECAM-K1" },
92 { V4L2_STD_SECAM_L, "SECAM-L" },
93 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
94 { 0, "Unknown" }
95};
96
97/* video4linux standard ID conversion to standard name
98 */
99const char *v4l2_norm_to_name(v4l2_std_id id)
100{
101 u32 myid = id;
102 int i;
103
104 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
105 64 bit comparations. So, on that architecture, with some gcc
106 variants, compilation fails. Currently, the max value is 30bit wide.
107 */
108 BUG_ON(myid != id);
109
110 for (i = 0; standards[i].std; i++)
111 if (myid == standards[i].std)
112 break;
113 return standards[i].descr;
114}
115EXPORT_SYMBOL(v4l2_norm_to_name);
116
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300117/* Returns frame period for the given standard */
118void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
119{
120 if (id & V4L2_STD_525_60) {
121 frameperiod->numerator = 1001;
122 frameperiod->denominator = 30000;
123 } else {
124 frameperiod->numerator = 1;
125 frameperiod->denominator = 25;
126 }
127}
128EXPORT_SYMBOL(v4l2_video_std_frame_period);
129
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300130/* Fill in the fields of a v4l2_standard structure according to the
131 'id' and 'transmission' parameters. Returns negative on error. */
132int v4l2_video_std_construct(struct v4l2_standard *vs,
133 int id, const char *name)
134{
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300135 vs->id = id;
136 v4l2_video_std_frame_period(id, &vs->frameperiod);
137 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300138 strlcpy(vs->name, name, sizeof(vs->name));
139 return 0;
140}
141EXPORT_SYMBOL(v4l2_video_std_construct);
142
143/* ----------------------------------------------------------------- */
144/* some arrays for pretty-printing debug messages of enum types */
145
146const char *v4l2_field_names[] = {
147 [V4L2_FIELD_ANY] = "any",
148 [V4L2_FIELD_NONE] = "none",
149 [V4L2_FIELD_TOP] = "top",
150 [V4L2_FIELD_BOTTOM] = "bottom",
151 [V4L2_FIELD_INTERLACED] = "interlaced",
152 [V4L2_FIELD_SEQ_TB] = "seq-tb",
153 [V4L2_FIELD_SEQ_BT] = "seq-bt",
154 [V4L2_FIELD_ALTERNATE] = "alternate",
155 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
156 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
157};
158EXPORT_SYMBOL(v4l2_field_names);
159
160const char *v4l2_type_names[] = {
161 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
162 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
163 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
164 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
165 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
166 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
167 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
168 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300169 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
170 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300171};
172EXPORT_SYMBOL(v4l2_type_names);
173
174static const char *v4l2_memory_names[] = {
175 [V4L2_MEMORY_MMAP] = "mmap",
176 [V4L2_MEMORY_USERPTR] = "userptr",
177 [V4L2_MEMORY_OVERLAY] = "overlay",
178};
179
180#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
181 arr[a] : "unknown")
182
183/* ------------------------------------------------------------------ */
184/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300185
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300186struct v4l2_ioctl_info {
187 unsigned int ioctl;
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300188 u16 flags;
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300189 const char * const name;
190};
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300191
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300192/* This control needs a priority check */
193#define INFO_FL_PRIO (1 << 0)
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300194/* This control can be valid if the filehandle passes a control handler. */
195#define INFO_FL_CTRL (1 << 1)
196
197#define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = { \
198 .ioctl = _ioctl, \
199 .flags = _flags, \
200 .name = #_ioctl, \
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300201}
202
203static struct v4l2_ioctl_info v4l2_ioctls[] = {
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300204 IOCTL_INFO(VIDIOC_QUERYCAP, 0),
205 IOCTL_INFO(VIDIOC_ENUM_FMT, 0),
206 IOCTL_INFO(VIDIOC_G_FMT, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300207 IOCTL_INFO(VIDIOC_S_FMT, INFO_FL_PRIO),
208 IOCTL_INFO(VIDIOC_REQBUFS, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300209 IOCTL_INFO(VIDIOC_QUERYBUF, 0),
210 IOCTL_INFO(VIDIOC_G_FBUF, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300211 IOCTL_INFO(VIDIOC_S_FBUF, INFO_FL_PRIO),
212 IOCTL_INFO(VIDIOC_OVERLAY, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300213 IOCTL_INFO(VIDIOC_QBUF, 0),
214 IOCTL_INFO(VIDIOC_DQBUF, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300215 IOCTL_INFO(VIDIOC_STREAMON, INFO_FL_PRIO),
216 IOCTL_INFO(VIDIOC_STREAMOFF, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300217 IOCTL_INFO(VIDIOC_G_PARM, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300218 IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300219 IOCTL_INFO(VIDIOC_G_STD, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300220 IOCTL_INFO(VIDIOC_S_STD, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300221 IOCTL_INFO(VIDIOC_ENUMSTD, 0),
222 IOCTL_INFO(VIDIOC_ENUMINPUT, 0),
223 IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300224 IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300225 IOCTL_INFO(VIDIOC_G_TUNER, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300226 IOCTL_INFO(VIDIOC_S_TUNER, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300227 IOCTL_INFO(VIDIOC_G_AUDIO, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300228 IOCTL_INFO(VIDIOC_S_AUDIO, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300229 IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL),
230 IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL),
231 IOCTL_INFO(VIDIOC_G_INPUT, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300232 IOCTL_INFO(VIDIOC_S_INPUT, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300233 IOCTL_INFO(VIDIOC_G_OUTPUT, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300234 IOCTL_INFO(VIDIOC_S_OUTPUT, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300235 IOCTL_INFO(VIDIOC_ENUMOUTPUT, 0),
236 IOCTL_INFO(VIDIOC_G_AUDOUT, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300237 IOCTL_INFO(VIDIOC_S_AUDOUT, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300238 IOCTL_INFO(VIDIOC_G_MODULATOR, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300239 IOCTL_INFO(VIDIOC_S_MODULATOR, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300240 IOCTL_INFO(VIDIOC_G_FREQUENCY, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300241 IOCTL_INFO(VIDIOC_S_FREQUENCY, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300242 IOCTL_INFO(VIDIOC_CROPCAP, 0),
243 IOCTL_INFO(VIDIOC_G_CROP, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300244 IOCTL_INFO(VIDIOC_S_CROP, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300245 IOCTL_INFO(VIDIOC_G_SELECTION, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300246 IOCTL_INFO(VIDIOC_S_SELECTION, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300247 IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300248 IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300249 IOCTL_INFO(VIDIOC_QUERYSTD, 0),
250 IOCTL_INFO(VIDIOC_TRY_FMT, 0),
251 IOCTL_INFO(VIDIOC_ENUMAUDIO, 0),
252 IOCTL_INFO(VIDIOC_ENUMAUDOUT, 0),
253 IOCTL_INFO(VIDIOC_G_PRIORITY, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300254 IOCTL_INFO(VIDIOC_S_PRIORITY, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300255 IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, 0),
256 IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
257 IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300258 IOCTL_INFO(VIDIOC_S_EXT_CTRLS, INFO_FL_PRIO | INFO_FL_CTRL),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300259 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, 0),
260 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, 0),
261 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, 0),
262 IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300263 IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300264 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300265 IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300266 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300267#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300268 IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
269 IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300270#endif
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300271 IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300272 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300273 IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300274 IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300275 IOCTL_INFO(VIDIOC_G_DV_PRESET, 0),
276 IOCTL_INFO(VIDIOC_QUERY_DV_PRESET, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300277 IOCTL_INFO(VIDIOC_S_DV_TIMINGS, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300278 IOCTL_INFO(VIDIOC_G_DV_TIMINGS, 0),
279 IOCTL_INFO(VIDIOC_DQEVENT, 0),
280 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
281 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300282 IOCTL_INFO(VIDIOC_CREATE_BUFS, INFO_FL_PRIO),
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300283 IOCTL_INFO(VIDIOC_PREPARE_BUF, 0),
Hans Verkuil5d7758e2012-05-15 08:06:44 -0300284 IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, 0),
285 IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, 0),
286 IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, 0),
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300287};
288#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
289
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300290bool v4l2_is_known_ioctl(unsigned int cmd)
291{
292 if (_IOC_NR(cmd) >= V4L2_IOCTLS)
293 return false;
294 return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
295}
296
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300297/* Common ioctl debug function. This function can be used by
298 external ioctl messages as well as internal V4L ioctl */
299void v4l_printk_ioctl(unsigned int cmd)
300{
301 char *dir, *type;
302
303 switch (_IOC_TYPE(cmd)) {
304 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300305 type = "v4l2_int";
306 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300307 case 'V':
308 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
309 type = "v4l2";
310 break;
311 }
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300312 printk("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300313 return;
314 default:
315 type = "unknown";
316 }
317
318 switch (_IOC_DIR(cmd)) {
319 case _IOC_NONE: dir = "--"; break;
320 case _IOC_READ: dir = "r-"; break;
321 case _IOC_WRITE: dir = "-w"; break;
322 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
323 default: dir = "*ERR*"; break;
324 }
325 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
326 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
327}
328EXPORT_SYMBOL(v4l_printk_ioctl);
329
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300330static void dbgbuf(unsigned int cmd, struct video_device *vfd,
331 struct v4l2_buffer *p)
332{
333 struct v4l2_timecode *tc = &p->timecode;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300334 struct v4l2_plane *plane;
335 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300336
337 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300338 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300339 p->timestamp.tv_sec / 3600,
340 (int)(p->timestamp.tv_sec / 60) % 60,
341 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300342 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300343 p->index,
344 prt_names(p->type, v4l2_type_names),
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300345 p->flags, p->field, p->sequence,
346 prt_names(p->memory, v4l2_memory_names));
347
348 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
349 for (i = 0; i < p->length; ++i) {
350 plane = &p->m.planes[i];
351 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
352 "offset/userptr=0x%08lx, length=%d\n",
353 i, plane->bytesused, plane->data_offset,
354 plane->m.userptr, plane->length);
355 }
356 } else {
357 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
358 p->bytesused, p->m.userptr, p->length);
359 }
360
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300361 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
362 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
363 tc->hours, tc->minutes, tc->seconds,
364 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
365}
366
367static inline void dbgrect(struct video_device *vfd, char *s,
368 struct v4l2_rect *r)
369{
370 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
371 r->width, r->height);
372};
373
Hans Verkuil5d7758e2012-05-15 08:06:44 -0300374static void dbgtimings(struct video_device *vfd,
375 const struct v4l2_dv_timings *p)
376{
377 switch (p->type) {
378 case V4L2_DV_BT_656_1120:
379 dbgarg2("bt-656/1120:interlaced=%d,"
380 " pixelclock=%lld,"
381 " width=%d, height=%d, polarities=%x,"
382 " hfrontporch=%d, hsync=%d,"
383 " hbackporch=%d, vfrontporch=%d,"
384 " vsync=%d, vbackporch=%d,"
385 " il_vfrontporch=%d, il_vsync=%d,"
386 " il_vbackporch=%d, standards=%x, flags=%x\n",
387 p->bt.interlaced, p->bt.pixelclock,
388 p->bt.width, p->bt.height,
389 p->bt.polarities, p->bt.hfrontporch,
390 p->bt.hsync, p->bt.hbackporch,
391 p->bt.vfrontporch, p->bt.vsync,
392 p->bt.vbackporch, p->bt.il_vfrontporch,
393 p->bt.il_vsync, p->bt.il_vbackporch,
394 p->bt.standards, p->bt.flags);
395 break;
396 default:
397 dbgarg2("Unknown type %d!\n", p->type);
398 break;
399 }
400}
401
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300402static inline void v4l_print_pix_fmt(struct video_device *vfd,
403 struct v4l2_pix_format *fmt)
404{
405 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
406 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
407 fmt->width, fmt->height,
408 (fmt->pixelformat & 0xff),
409 (fmt->pixelformat >> 8) & 0xff,
410 (fmt->pixelformat >> 16) & 0xff,
411 (fmt->pixelformat >> 24) & 0xff,
412 prt_names(fmt->field, v4l2_field_names),
413 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
414};
415
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300416static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
417 struct v4l2_pix_format_mplane *fmt)
418{
419 int i;
420
421 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
422 "colorspace=%d, num_planes=%d\n",
423 fmt->width, fmt->height,
424 (fmt->pixelformat & 0xff),
425 (fmt->pixelformat >> 8) & 0xff,
426 (fmt->pixelformat >> 16) & 0xff,
427 (fmt->pixelformat >> 24) & 0xff,
428 prt_names(fmt->field, v4l2_field_names),
429 fmt->colorspace, fmt->num_planes);
430
431 for (i = 0; i < fmt->num_planes; ++i)
432 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
433 fmt->plane_fmt[i].bytesperline,
434 fmt->plane_fmt[i].sizeimage);
435}
436
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300437static inline void v4l_print_ext_ctrls(unsigned int cmd,
438 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
439{
440 __u32 i;
441
442 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
443 return;
444 dbgarg(cmd, "");
445 printk(KERN_CONT "class=0x%x", c->ctrl_class);
446 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300447 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300448 printk(KERN_CONT " id/val=0x%x/0x%x",
449 c->controls[i].id, c->controls[i].value);
450 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300451 printk(KERN_CONT " id=0x%x,size=%u",
452 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300453 }
454 printk(KERN_CONT "\n");
455};
456
457static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
458{
459 __u32 i;
460
461 /* zero the reserved fields */
462 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300463 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300464 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300465
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300466 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
467 when using extended controls.
468 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
469 is it allowed for backwards compatibility.
470 */
471 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
472 return 0;
473 /* Check that all controls are from the same control class. */
474 for (i = 0; i < c->count; i++) {
475 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
476 c->error_idx = i;
477 return 0;
478 }
479 }
480 return 1;
481}
482
Hans Verkuila3998102008-07-21 02:57:38 -0300483static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300484{
Hans Verkuila3998102008-07-21 02:57:38 -0300485 if (ops == NULL)
486 return -EINVAL;
487
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300488 switch (type) {
489 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300490 if (ops->vidioc_g_fmt_vid_cap ||
491 ops->vidioc_g_fmt_vid_cap_mplane)
492 return 0;
493 break;
494 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
495 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300496 return 0;
497 break;
498 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300499 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300500 return 0;
501 break;
502 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300503 if (ops->vidioc_g_fmt_vid_out ||
504 ops->vidioc_g_fmt_vid_out_mplane)
505 return 0;
506 break;
507 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
508 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300509 return 0;
510 break;
511 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300512 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300513 return 0;
514 break;
515 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300516 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300517 return 0;
518 break;
519 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300520 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300521 return 0;
522 break;
523 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300524 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300525 return 0;
526 break;
527 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300528 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300529 return 0;
530 break;
531 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300532 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300533 return 0;
534 break;
535 }
536 return -EINVAL;
537}
538
Hans Verkuil069b7472008-12-30 07:04:34 -0300539static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300540 unsigned int cmd, void *arg)
541{
542 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300543 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300544 void *fh = file->private_data;
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300545 struct v4l2_fh *vfh = NULL;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300546 int use_fh_prio = 0;
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300547 long ret = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300548
Hans Verkuil6a717882010-04-06 15:56:08 -0300549 if (ops == NULL) {
550 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
551 vfd->name);
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300552 return ret;
Hans Verkuil6a717882010-04-06 15:56:08 -0300553 }
554
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300555 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
556 vfh = file->private_data;
557 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300558 }
559
560 if (v4l2_is_known_ioctl(cmd)) {
561 struct v4l2_ioctl_info *info = &v4l2_ioctls[_IOC_NR(cmd)];
562
563 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
564 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
565 return -ENOTTY;
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300566
567 if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
568 ret = v4l2_prio_check(vfd->prio, vfh->prio);
569 if (ret)
570 return ret;
571 }
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300572 }
573
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300574 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
575 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
576 v4l_print_ioctl(vfd->name, cmd);
577 printk(KERN_CONT "\n");
578 }
579
Hans Verkuil6a717882010-04-06 15:56:08 -0300580 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300581
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300582 /* --- capabilities ------------------------------------------ */
583 case VIDIOC_QUERYCAP:
584 {
585 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300586
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -0300587 cap->version = LINUX_VERSION_CODE;
Hans Verkuila3998102008-07-21 02:57:38 -0300588 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300589 if (!ret)
590 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
591 "version=0x%08x, "
Hans Verkuil583aa3a2012-01-11 06:45:05 -0300592 "capabilities=0x%08x, "
593 "device_caps=0x%08x\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300594 cap->driver, cap->card, cap->bus_info,
595 cap->version,
Hans Verkuil583aa3a2012-01-11 06:45:05 -0300596 cap->capabilities,
597 cap->device_caps);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300598 break;
599 }
600
601 /* --- priority ------------------------------------------ */
602 case VIDIOC_G_PRIORITY:
603 {
604 enum v4l2_priority *p = arg;
605
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300606 if (ops->vidioc_g_priority) {
607 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300608 } else if (use_fh_prio) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300609 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
610 ret = 0;
611 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300612 if (!ret)
613 dbgarg(cmd, "priority is %d\n", *p);
614 break;
615 }
616 case VIDIOC_S_PRIORITY:
617 {
618 enum v4l2_priority *p = arg;
619
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300620 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300621 if (ops->vidioc_s_priority)
622 ret = ops->vidioc_s_priority(file, fh, *p);
623 else
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300624 ret = v4l2_prio_change(&vfd->v4l2_dev->prio,
Hans Verkuil93d5a302011-08-09 09:32:06 -0300625 &vfh->prio, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300626 break;
627 }
628
629 /* --- capture ioctls ---------------------------------------- */
630 case VIDIOC_ENUM_FMT:
631 {
632 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300633
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300634 ret = -EINVAL;
Trent Piepho19c96e42009-03-04 01:21:02 -0300635 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300636 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300637 if (likely(ops->vidioc_enum_fmt_vid_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300638 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300639 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300640 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300641 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300642 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
643 fh, f);
644 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300645 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300646 if (likely(ops->vidioc_enum_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300647 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300648 fh, f);
649 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300650 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300651 if (likely(ops->vidioc_enum_fmt_vid_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300652 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300653 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300654 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300655 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300656 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
657 fh, f);
658 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300659 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300660 if (likely(ops->vidioc_enum_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300661 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300662 fh, f);
663 break;
664 default:
665 break;
666 }
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300667 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300668 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
669 "pixelformat=%c%c%c%c, description='%s'\n",
670 f->index, f->type, f->flags,
671 (f->pixelformat & 0xff),
672 (f->pixelformat >> 8) & 0xff,
673 (f->pixelformat >> 16) & 0xff,
674 (f->pixelformat >> 24) & 0xff,
675 f->description);
676 break;
677 }
678 case VIDIOC_G_FMT:
679 {
680 struct v4l2_format *f = (struct v4l2_format *)arg;
681
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300682 /* FIXME: Should be one dump per type */
683 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
684
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300685 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300686 switch (f->type) {
687 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300688 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300689 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300690 if (!ret)
691 v4l_print_pix_fmt(vfd, &f->fmt.pix);
692 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300693 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300694 if (ops->vidioc_g_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300695 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
696 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300697 if (!ret)
698 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
699 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300700 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300701 if (likely(ops->vidioc_g_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300702 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300703 fh, f);
704 break;
705 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300706 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300707 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300708 if (!ret)
709 v4l_print_pix_fmt(vfd, &f->fmt.pix);
710 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300711 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300712 if (ops->vidioc_g_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300713 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
714 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300715 if (!ret)
716 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
717 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300718 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300719 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300720 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300721 fh, f);
722 break;
723 case V4L2_BUF_TYPE_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300724 if (likely(ops->vidioc_g_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300725 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300726 break;
727 case V4L2_BUF_TYPE_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300728 if (likely(ops->vidioc_g_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300729 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300730 break;
731 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300732 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300733 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300734 fh, f);
735 break;
736 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300737 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300738 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300739 fh, f);
740 break;
741 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300742 if (likely(ops->vidioc_g_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300743 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300744 fh, f);
745 break;
746 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300747 break;
748 }
749 case VIDIOC_S_FMT:
750 {
751 struct v4l2_format *f = (struct v4l2_format *)arg;
752
Hans Verkuil93d5a302011-08-09 09:32:06 -0300753 ret = -EINVAL;
754
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300755 /* FIXME: Should be one dump per type */
756 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
757
758 switch (f->type) {
759 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300760 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300761 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300762 if (ops->vidioc_s_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300763 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300764 break;
765 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
766 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
767 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300768 if (ops->vidioc_s_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300769 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
770 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300771 break;
772 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300773 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300774 if (ops->vidioc_s_fmt_vid_overlay)
775 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300776 fh, f);
777 break;
778 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300779 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300780 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300781 if (ops->vidioc_s_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300782 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300783 break;
784 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
785 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
786 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300787 if (ops->vidioc_s_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300788 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
789 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300790 break;
791 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300792 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300793 if (ops->vidioc_s_fmt_vid_out_overlay)
794 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300795 fh, f);
796 break;
797 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300798 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300799 if (likely(ops->vidioc_s_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300800 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300801 break;
802 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300803 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300804 if (likely(ops->vidioc_s_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300805 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300806 break;
807 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300808 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300809 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300810 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300811 fh, f);
812 break;
813 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300814 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300815 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300816 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300817 fh, f);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300818
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300819 break;
820 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300821 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300822 if (likely(ops->vidioc_s_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300823 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300824 fh, f);
825 break;
826 }
827 break;
828 }
829 case VIDIOC_TRY_FMT:
830 {
831 struct v4l2_format *f = (struct v4l2_format *)arg;
832
833 /* FIXME: Should be one dump per type */
834 dbgarg(cmd, "type=%s\n", prt_names(f->type,
835 v4l2_type_names));
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300836 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300837 switch (f->type) {
838 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300839 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300840 if (ops->vidioc_try_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300841 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300842 if (!ret)
843 v4l_print_pix_fmt(vfd, &f->fmt.pix);
844 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300845 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
846 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300847 if (ops->vidioc_try_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300848 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
849 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300850 if (!ret)
851 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
852 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300853 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300854 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300855 if (likely(ops->vidioc_try_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300856 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300857 fh, f);
858 break;
859 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300860 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300861 if (ops->vidioc_try_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300862 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300863 if (!ret)
864 v4l_print_pix_fmt(vfd, &f->fmt.pix);
865 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300866 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
867 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300868 if (ops->vidioc_try_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300869 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
870 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300871 if (!ret)
872 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
873 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300874 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300875 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300876 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300877 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300878 fh, f);
879 break;
880 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300881 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300882 if (likely(ops->vidioc_try_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300883 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300884 break;
885 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300886 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300887 if (likely(ops->vidioc_try_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300888 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300889 break;
890 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300891 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300892 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300893 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300894 fh, f);
895 break;
896 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300897 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300898 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300899 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300900 fh, f);
901 break;
902 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300903 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300904 if (likely(ops->vidioc_try_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300905 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300906 fh, f);
907 break;
908 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300909 break;
910 }
911 /* FIXME: Those buf reqs could be handled here,
912 with some changes on videobuf to allow its header to be included at
913 videodev2.h or being merged at videodev2.
914 */
915 case VIDIOC_REQBUFS:
916 {
917 struct v4l2_requestbuffers *p = arg;
918
Hans Verkuila3998102008-07-21 02:57:38 -0300919 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300920 if (ret)
921 break;
922
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300923 if (p->type < V4L2_BUF_TYPE_PRIVATE)
924 CLEAR_AFTER_FIELD(p, memory);
925
Hans Verkuila3998102008-07-21 02:57:38 -0300926 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300927 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
928 p->count,
929 prt_names(p->type, v4l2_type_names),
930 prt_names(p->memory, v4l2_memory_names));
931 break;
932 }
933 case VIDIOC_QUERYBUF:
934 {
935 struct v4l2_buffer *p = arg;
936
Hans Verkuila3998102008-07-21 02:57:38 -0300937 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300938 if (ret)
939 break;
940
Hans Verkuila3998102008-07-21 02:57:38 -0300941 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300942 if (!ret)
943 dbgbuf(cmd, vfd, p);
944 break;
945 }
946 case VIDIOC_QBUF:
947 {
948 struct v4l2_buffer *p = arg;
949
Hans Verkuila3998102008-07-21 02:57:38 -0300950 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300951 if (ret)
952 break;
953
Hans Verkuila3998102008-07-21 02:57:38 -0300954 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300955 if (!ret)
956 dbgbuf(cmd, vfd, p);
957 break;
958 }
959 case VIDIOC_DQBUF:
960 {
961 struct v4l2_buffer *p = arg;
962
Hans Verkuila3998102008-07-21 02:57:38 -0300963 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300964 if (ret)
965 break;
966
Hans Verkuila3998102008-07-21 02:57:38 -0300967 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300968 if (!ret)
969 dbgbuf(cmd, vfd, p);
970 break;
971 }
972 case VIDIOC_OVERLAY:
973 {
974 int *i = arg;
975
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300976 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -0300977 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300978 break;
979 }
980 case VIDIOC_G_FBUF:
981 {
982 struct v4l2_framebuffer *p = arg;
983
Hans Verkuila3998102008-07-21 02:57:38 -0300984 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300985 if (!ret) {
986 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
987 p->capability, p->flags,
988 (unsigned long)p->base);
989 v4l_print_pix_fmt(vfd, &p->fmt);
990 }
991 break;
992 }
993 case VIDIOC_S_FBUF:
994 {
995 struct v4l2_framebuffer *p = arg;
996
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300997 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
998 p->capability, p->flags, (unsigned long)p->base);
999 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -03001000 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001001 break;
1002 }
1003 case VIDIOC_STREAMON:
1004 {
1005 enum v4l2_buf_type i = *(int *)arg;
1006
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001007 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001008 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001009 break;
1010 }
1011 case VIDIOC_STREAMOFF:
1012 {
1013 enum v4l2_buf_type i = *(int *)arg;
1014
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001015 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001016 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001017 break;
1018 }
1019 /* ---------- tv norms ---------- */
1020 case VIDIOC_ENUMSTD:
1021 {
1022 struct v4l2_standard *p = arg;
1023 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1024 unsigned int index = p->index, i, j = 0;
1025 const char *descr = "";
1026
Hans Verkuil93d5a302011-08-09 09:32:06 -03001027 if (id == 0)
1028 break;
1029 ret = -EINVAL;
1030
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001031 /* Return norm array in a canonical way */
1032 for (i = 0; i <= index && id; i++) {
1033 /* last std value in the standards array is 0, so this
1034 while always ends there since (id & 0) == 0. */
1035 while ((id & standards[j].std) != standards[j].std)
1036 j++;
1037 curr_id = standards[j].std;
1038 descr = standards[j].descr;
1039 j++;
1040 if (curr_id == 0)
1041 break;
1042 if (curr_id != V4L2_STD_PAL &&
1043 curr_id != V4L2_STD_SECAM &&
1044 curr_id != V4L2_STD_NTSC)
1045 id &= ~curr_id;
1046 }
1047 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001048 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001049
1050 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001051
1052 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1053 "framelines=%d\n", p->index,
1054 (unsigned long long)p->id, p->name,
1055 p->frameperiod.numerator,
1056 p->frameperiod.denominator,
1057 p->framelines);
1058
1059 ret = 0;
1060 break;
1061 }
1062 case VIDIOC_G_STD:
1063 {
1064 v4l2_std_id *id = arg;
1065
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001066 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001067 if (ops->vidioc_g_std)
1068 ret = ops->vidioc_g_std(file, fh, id);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001069 else if (vfd->current_norm) {
1070 ret = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001071 *id = vfd->current_norm;
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001072 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001073
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001074 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001075 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1076 break;
1077 }
1078 case VIDIOC_S_STD:
1079 {
1080 v4l2_std_id *id = arg, norm;
1081
1082 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1083
Hans Verkuil93d5a302011-08-09 09:32:06 -03001084 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001085 norm = (*id) & vfd->tvnorms;
1086 if (vfd->tvnorms && !norm) /* Check if std is supported */
1087 break;
1088
1089 /* Calls the specific handler */
Hans Verkuil93d5a302011-08-09 09:32:06 -03001090 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001091
1092 /* Updates standard information */
1093 if (ret >= 0)
1094 vfd->current_norm = norm;
1095 break;
1096 }
1097 case VIDIOC_QUERYSTD:
1098 {
1099 v4l2_std_id *p = arg;
1100
Mauro Carvalho Chehab8715e6c2011-10-04 09:32:23 -03001101 /*
1102 * If nothing detected, it should return all supported
1103 * Drivers just need to mask the std argument, in order
1104 * to remove the standards that don't apply from the mask.
1105 * This means that tuners, audio and video decoders can join
1106 * their efforts to improve the standards detection
1107 */
1108 *p = vfd->tvnorms;
Hans Verkuila3998102008-07-21 02:57:38 -03001109 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001110 if (!ret)
1111 dbgarg(cmd, "detected std=%08Lx\n",
1112 (unsigned long long)*p);
1113 break;
1114 }
1115 /* ------ input switching ---------- */
1116 /* FIXME: Inputs can be handled inside videodev2 */
1117 case VIDIOC_ENUMINPUT:
1118 {
1119 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001120
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001121 /*
1122 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1123 * CAP_STD here based on ioctl handler provided by the
1124 * driver. If the driver doesn't support these
1125 * for a specific input, it must override these flags.
1126 */
1127 if (ops->vidioc_s_std)
1128 p->capabilities |= V4L2_IN_CAP_STD;
1129 if (ops->vidioc_s_dv_preset)
1130 p->capabilities |= V4L2_IN_CAP_PRESETS;
1131 if (ops->vidioc_s_dv_timings)
1132 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1133
Hans Verkuila3998102008-07-21 02:57:38 -03001134 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001135 if (!ret)
1136 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1137 "audioset=%d, "
1138 "tuner=%d, std=%08Lx, status=%d\n",
1139 p->index, p->name, p->type, p->audioset,
1140 p->tuner,
1141 (unsigned long long)p->std,
1142 p->status);
1143 break;
1144 }
1145 case VIDIOC_G_INPUT:
1146 {
1147 unsigned int *i = arg;
1148
Hans Verkuila3998102008-07-21 02:57:38 -03001149 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001150 if (!ret)
1151 dbgarg(cmd, "value=%d\n", *i);
1152 break;
1153 }
1154 case VIDIOC_S_INPUT:
1155 {
1156 unsigned int *i = arg;
1157
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001158 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001159 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001160 break;
1161 }
1162
1163 /* ------ output switching ---------- */
1164 case VIDIOC_ENUMOUTPUT:
1165 {
1166 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001167
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001168 /*
1169 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1170 * CAP_STD here based on ioctl handler provided by the
1171 * driver. If the driver doesn't support these
1172 * for a specific output, it must override these flags.
1173 */
1174 if (ops->vidioc_s_std)
1175 p->capabilities |= V4L2_OUT_CAP_STD;
1176 if (ops->vidioc_s_dv_preset)
1177 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1178 if (ops->vidioc_s_dv_timings)
1179 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1180
Hans Verkuila3998102008-07-21 02:57:38 -03001181 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001182 if (!ret)
1183 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1184 "audioset=0x%x, "
1185 "modulator=%d, std=0x%08Lx\n",
1186 p->index, p->name, p->type, p->audioset,
1187 p->modulator, (unsigned long long)p->std);
1188 break;
1189 }
1190 case VIDIOC_G_OUTPUT:
1191 {
1192 unsigned int *i = arg;
1193
Hans Verkuila3998102008-07-21 02:57:38 -03001194 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001195 if (!ret)
1196 dbgarg(cmd, "value=%d\n", *i);
1197 break;
1198 }
1199 case VIDIOC_S_OUTPUT:
1200 {
1201 unsigned int *i = arg;
1202
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001203 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001204 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001205 break;
1206 }
1207
1208 /* --- controls ---------------------------------------------- */
1209 case VIDIOC_QUERYCTRL:
1210 {
1211 struct v4l2_queryctrl *p = arg;
1212
Hans Verkuil2d28b682011-03-12 08:54:43 -03001213 if (vfh && vfh->ctrl_handler)
1214 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1215 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001216 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1217 else if (ops->vidioc_queryctrl)
1218 ret = ops->vidioc_queryctrl(file, fh, p);
1219 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001220 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001221 if (!ret)
1222 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1223 "step=%d, default=%d, flags=0x%08x\n",
1224 p->id, p->type, p->name,
1225 p->minimum, p->maximum,
1226 p->step, p->default_value, p->flags);
1227 else
1228 dbgarg(cmd, "id=0x%x\n", p->id);
1229 break;
1230 }
1231 case VIDIOC_G_CTRL:
1232 {
1233 struct v4l2_control *p = arg;
1234
Hans Verkuil2d28b682011-03-12 08:54:43 -03001235 if (vfh && vfh->ctrl_handler)
1236 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1237 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001238 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1239 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001240 ret = ops->vidioc_g_ctrl(file, fh, p);
1241 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001242 struct v4l2_ext_controls ctrls;
1243 struct v4l2_ext_control ctrl;
1244
1245 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1246 ctrls.count = 1;
1247 ctrls.controls = &ctrl;
1248 ctrl.id = p->id;
1249 ctrl.value = p->value;
1250 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001251 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001252 if (ret == 0)
1253 p->value = ctrl.value;
1254 }
1255 } else
1256 break;
1257 if (!ret)
1258 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1259 else
1260 dbgarg(cmd, "id=0x%x\n", p->id);
1261 break;
1262 }
1263 case VIDIOC_S_CTRL:
1264 {
1265 struct v4l2_control *p = arg;
1266 struct v4l2_ext_controls ctrls;
1267 struct v4l2_ext_control ctrl;
1268
Hans Verkuil2d28b682011-03-12 08:54:43 -03001269 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001270 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001271 break;
1272
1273 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1274
Hans Verkuil2d28b682011-03-12 08:54:43 -03001275 if (vfh && vfh->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001276 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001277 break;
1278 }
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001279 if (vfd->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001280 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001281 break;
1282 }
Hans Verkuila3998102008-07-21 02:57:38 -03001283 if (ops->vidioc_s_ctrl) {
1284 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001285 break;
1286 }
Hans Verkuila3998102008-07-21 02:57:38 -03001287 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001288 break;
1289
1290 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1291 ctrls.count = 1;
1292 ctrls.controls = &ctrl;
1293 ctrl.id = p->id;
1294 ctrl.value = p->value;
1295 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001296 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001297 else
1298 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001299 break;
1300 }
1301 case VIDIOC_G_EXT_CTRLS:
1302 {
1303 struct v4l2_ext_controls *p = arg;
1304
1305 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001306 if (vfh && vfh->ctrl_handler)
1307 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1308 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001309 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001310 else if (ops->vidioc_g_ext_ctrls)
1311 ret = check_ext_ctrls(p, 0) ?
1312 ops->vidioc_g_ext_ctrls(file, fh, p) :
1313 -EINVAL;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001314 else
1315 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001316 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1317 break;
1318 }
1319 case VIDIOC_S_EXT_CTRLS:
1320 {
1321 struct v4l2_ext_controls *p = arg;
1322
1323 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001324 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1325 !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001326 break;
1327 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001328 if (vfh && vfh->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001329 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001330 else if (vfd->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001331 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001332 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001333 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001334 else
1335 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001336 break;
1337 }
1338 case VIDIOC_TRY_EXT_CTRLS:
1339 {
1340 struct v4l2_ext_controls *p = arg;
1341
1342 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001343 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1344 !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001345 break;
1346 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001347 if (vfh && vfh->ctrl_handler)
1348 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1349 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001350 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1351 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001352 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001353 else
1354 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001355 break;
1356 }
1357 case VIDIOC_QUERYMENU:
1358 {
1359 struct v4l2_querymenu *p = arg;
1360
Hans Verkuil2d28b682011-03-12 08:54:43 -03001361 if (vfh && vfh->ctrl_handler)
1362 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1363 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001364 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1365 else if (ops->vidioc_querymenu)
1366 ret = ops->vidioc_querymenu(file, fh, p);
1367 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001368 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001369 if (!ret)
1370 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1371 p->id, p->index, p->name);
1372 else
1373 dbgarg(cmd, "id=0x%x, index=%d\n",
1374 p->id, p->index);
1375 break;
1376 }
1377 /* --- audio ---------------------------------------------- */
1378 case VIDIOC_ENUMAUDIO:
1379 {
1380 struct v4l2_audio *p = arg;
1381
Hans Verkuila3998102008-07-21 02:57:38 -03001382 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001383 if (!ret)
1384 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1385 "mode=0x%x\n", p->index, p->name,
1386 p->capability, p->mode);
1387 else
1388 dbgarg(cmd, "index=%d\n", p->index);
1389 break;
1390 }
1391 case VIDIOC_G_AUDIO:
1392 {
1393 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001394
Hans Verkuila3998102008-07-21 02:57:38 -03001395 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001396 if (!ret)
1397 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1398 "mode=0x%x\n", p->index,
1399 p->name, p->capability, p->mode);
1400 else
1401 dbgarg(cmd, "index=%d\n", p->index);
1402 break;
1403 }
1404 case VIDIOC_S_AUDIO:
1405 {
1406 struct v4l2_audio *p = arg;
1407
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001408 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1409 "mode=0x%x\n", p->index, p->name,
1410 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001411 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001412 break;
1413 }
1414 case VIDIOC_ENUMAUDOUT:
1415 {
1416 struct v4l2_audioout *p = arg;
1417
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001418 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001419 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001420 if (!ret)
1421 dbgarg2("index=%d, name=%s, capability=%d, "
1422 "mode=%d\n", p->index, p->name,
1423 p->capability, p->mode);
1424 break;
1425 }
1426 case VIDIOC_G_AUDOUT:
1427 {
1428 struct v4l2_audioout *p = arg;
1429
Hans Verkuila3998102008-07-21 02:57:38 -03001430 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001431 if (!ret)
1432 dbgarg2("index=%d, name=%s, capability=%d, "
1433 "mode=%d\n", p->index, p->name,
1434 p->capability, p->mode);
1435 break;
1436 }
1437 case VIDIOC_S_AUDOUT:
1438 {
1439 struct v4l2_audioout *p = arg;
1440
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001441 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1442 "mode=%d\n", p->index, p->name,
1443 p->capability, p->mode);
1444
Hans Verkuila3998102008-07-21 02:57:38 -03001445 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001446 break;
1447 }
1448 case VIDIOC_G_MODULATOR:
1449 {
1450 struct v4l2_modulator *p = arg;
1451
Hans Verkuila3998102008-07-21 02:57:38 -03001452 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001453 if (!ret)
1454 dbgarg(cmd, "index=%d, name=%s, "
1455 "capability=%d, rangelow=%d,"
1456 " rangehigh=%d, txsubchans=%d\n",
1457 p->index, p->name, p->capability,
1458 p->rangelow, p->rangehigh,
1459 p->txsubchans);
1460 break;
1461 }
1462 case VIDIOC_S_MODULATOR:
1463 {
1464 struct v4l2_modulator *p = arg;
1465
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001466 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1467 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1468 p->index, p->name, p->capability, p->rangelow,
1469 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001470 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001471 break;
1472 }
1473 case VIDIOC_G_CROP:
1474 {
1475 struct v4l2_crop *p = arg;
1476
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001477 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001478
1479 if (ops->vidioc_g_crop) {
1480 ret = ops->vidioc_g_crop(file, fh, p);
1481 } else {
1482 /* simulate capture crop using selection api */
1483 struct v4l2_selection s = {
1484 .type = p->type,
1485 };
1486
1487 /* crop means compose for output devices */
1488 if (V4L2_TYPE_IS_OUTPUT(p->type))
1489 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1490 else
1491 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1492
1493 ret = ops->vidioc_g_selection(file, fh, &s);
1494
1495 /* copying results to old structure on success */
1496 if (!ret)
1497 p->c = s.r;
1498 }
1499
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001500 if (!ret)
1501 dbgrect(vfd, "", &p->c);
1502 break;
1503 }
1504 case VIDIOC_S_CROP:
1505 {
1506 struct v4l2_crop *p = arg;
1507
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001508 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1509 dbgrect(vfd, "", &p->c);
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001510
1511 if (ops->vidioc_s_crop) {
1512 ret = ops->vidioc_s_crop(file, fh, p);
1513 } else {
1514 /* simulate capture crop using selection api */
1515 struct v4l2_selection s = {
1516 .type = p->type,
1517 .r = p->c,
1518 };
1519
1520 /* crop means compose for output devices */
1521 if (V4L2_TYPE_IS_OUTPUT(p->type))
1522 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1523 else
1524 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1525
1526 ret = ops->vidioc_s_selection(file, fh, &s);
1527 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001528 break;
1529 }
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001530 case VIDIOC_G_SELECTION:
1531 {
1532 struct v4l2_selection *p = arg;
1533
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001534 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1535
1536 ret = ops->vidioc_g_selection(file, fh, p);
1537 if (!ret)
1538 dbgrect(vfd, "", &p->r);
1539 break;
1540 }
1541 case VIDIOC_S_SELECTION:
1542 {
1543 struct v4l2_selection *p = arg;
1544
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001545
1546 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1547 dbgrect(vfd, "", &p->r);
1548
1549 ret = ops->vidioc_s_selection(file, fh, p);
1550 break;
1551 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001552 case VIDIOC_CROPCAP:
1553 {
1554 struct v4l2_cropcap *p = arg;
1555
1556 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001557 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001558 if (ops->vidioc_cropcap) {
1559 ret = ops->vidioc_cropcap(file, fh, p);
1560 } else {
1561 struct v4l2_selection s = { .type = p->type };
1562
1563 /* obtaining bounds */
1564 if (V4L2_TYPE_IS_OUTPUT(p->type))
1565 s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
1566 else
1567 s.target = V4L2_SEL_TGT_CROP_BOUNDS;
1568
1569 ret = ops->vidioc_g_selection(file, fh, &s);
1570 if (ret)
1571 break;
1572 p->bounds = s.r;
1573
1574 /* obtaining defrect */
1575 if (V4L2_TYPE_IS_OUTPUT(p->type))
1576 s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
1577 else
1578 s.target = V4L2_SEL_TGT_CROP_DEFAULT;
1579
1580 ret = ops->vidioc_g_selection(file, fh, &s);
1581 if (ret)
1582 break;
1583 p->defrect = s.r;
1584
1585 /* setting trivial pixelaspect */
1586 p->pixelaspect.numerator = 1;
1587 p->pixelaspect.denominator = 1;
1588 }
1589
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001590 if (!ret) {
1591 dbgrect(vfd, "bounds ", &p->bounds);
1592 dbgrect(vfd, "defrect ", &p->defrect);
1593 }
1594 break;
1595 }
1596 case VIDIOC_G_JPEGCOMP:
1597 {
1598 struct v4l2_jpegcompression *p = arg;
1599
Hans Verkuila3998102008-07-21 02:57:38 -03001600 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001601 if (!ret)
1602 dbgarg(cmd, "quality=%d, APPn=%d, "
1603 "APP_len=%d, COM_len=%d, "
1604 "jpeg_markers=%d\n",
1605 p->quality, p->APPn, p->APP_len,
1606 p->COM_len, p->jpeg_markers);
1607 break;
1608 }
1609 case VIDIOC_S_JPEGCOMP:
1610 {
1611 struct v4l2_jpegcompression *p = arg;
1612
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001613 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1614 "COM_len=%d, jpeg_markers=%d\n",
1615 p->quality, p->APPn, p->APP_len,
1616 p->COM_len, p->jpeg_markers);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001617 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001618 break;
1619 }
1620 case VIDIOC_G_ENC_INDEX:
1621 {
1622 struct v4l2_enc_idx *p = arg;
1623
Hans Verkuila3998102008-07-21 02:57:38 -03001624 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001625 if (!ret)
1626 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1627 p->entries, p->entries_cap);
1628 break;
1629 }
1630 case VIDIOC_ENCODER_CMD:
1631 {
1632 struct v4l2_encoder_cmd *p = arg;
1633
Hans Verkuila3998102008-07-21 02:57:38 -03001634 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001635 if (!ret)
1636 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1637 break;
1638 }
1639 case VIDIOC_TRY_ENCODER_CMD:
1640 {
1641 struct v4l2_encoder_cmd *p = arg;
1642
Hans Verkuila3998102008-07-21 02:57:38 -03001643 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001644 if (!ret)
1645 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1646 break;
1647 }
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001648 case VIDIOC_DECODER_CMD:
1649 {
1650 struct v4l2_decoder_cmd *p = arg;
1651
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001652 ret = ops->vidioc_decoder_cmd(file, fh, p);
1653 if (!ret)
1654 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1655 break;
1656 }
1657 case VIDIOC_TRY_DECODER_CMD:
1658 {
1659 struct v4l2_decoder_cmd *p = arg;
1660
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001661 ret = ops->vidioc_try_decoder_cmd(file, fh, p);
1662 if (!ret)
1663 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1664 break;
1665 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001666 case VIDIOC_G_PARM:
1667 {
1668 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001669
Hans Verkuila3998102008-07-21 02:57:38 -03001670 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001671 ret = check_fmt(ops, p->type);
1672 if (ret)
1673 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001674 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001675 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001676 v4l2_std_id std = vfd->current_norm;
1677
Hans Verkuil93d5a302011-08-09 09:32:06 -03001678 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001679 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001680 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001681
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001682 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001683 if (ops->vidioc_g_std)
1684 ret = ops->vidioc_g_std(file, fh, &std);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001685 if (ret == 0)
1686 v4l2_video_std_frame_period(std,
1687 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001688 }
1689
1690 dbgarg(cmd, "type=%d\n", p->type);
1691 break;
1692 }
1693 case VIDIOC_S_PARM:
1694 {
1695 struct v4l2_streamparm *p = arg;
1696
Trent Piepho34796bc2009-03-28 22:25:35 -03001697 ret = check_fmt(ops, p->type);
1698 if (ret)
1699 break;
1700
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001701 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001702 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001703 break;
1704 }
1705 case VIDIOC_G_TUNER:
1706 {
1707 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001708
Hans Verkuil227690d2011-06-12 06:36:41 -03001709 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1710 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001711 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001712 if (!ret)
1713 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1714 "capability=0x%x, rangelow=%d, "
1715 "rangehigh=%d, signal=%d, afc=%d, "
1716 "rxsubchans=0x%x, audmode=%d\n",
1717 p->index, p->name, p->type,
1718 p->capability, p->rangelow,
1719 p->rangehigh, p->signal, p->afc,
1720 p->rxsubchans, p->audmode);
1721 break;
1722 }
1723 case VIDIOC_S_TUNER:
1724 {
1725 struct v4l2_tuner *p = arg;
1726
Hans Verkuil227690d2011-06-12 06:36:41 -03001727 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1728 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001729 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1730 "capability=0x%x, rangelow=%d, "
1731 "rangehigh=%d, signal=%d, afc=%d, "
1732 "rxsubchans=0x%x, audmode=%d\n",
1733 p->index, p->name, p->type,
1734 p->capability, p->rangelow,
1735 p->rangehigh, p->signal, p->afc,
1736 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001737 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001738 break;
1739 }
1740 case VIDIOC_G_FREQUENCY:
1741 {
1742 struct v4l2_frequency *p = arg;
1743
Hans Verkuil227690d2011-06-12 06:36:41 -03001744 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1745 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001746 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001747 if (!ret)
1748 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1749 p->tuner, p->type, p->frequency);
1750 break;
1751 }
1752 case VIDIOC_S_FREQUENCY:
1753 {
1754 struct v4l2_frequency *p = arg;
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001755 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001756
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001757 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1758 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001759 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1760 p->tuner, p->type, p->frequency);
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001761 if (p->type != type)
1762 ret = -EINVAL;
1763 else
1764 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001765 break;
1766 }
1767 case VIDIOC_G_SLICED_VBI_CAP:
1768 {
1769 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001770
Trent Piepho19c96e42009-03-04 01:21:02 -03001771 /* Clear up to type, everything after type is zerod already */
1772 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1773
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001774 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001775 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001776 if (!ret)
1777 dbgarg2("service_set=%d\n", p->service_set);
1778 break;
1779 }
1780 case VIDIOC_LOG_STATUS:
1781 {
Hans Verkuile2ecb252012-02-02 08:20:53 -03001782 if (vfd->v4l2_dev)
1783 pr_info("%s: ================= START STATUS =================\n",
1784 vfd->v4l2_dev->name);
Hans Verkuila3998102008-07-21 02:57:38 -03001785 ret = ops->vidioc_log_status(file, fh);
Hans Verkuile2ecb252012-02-02 08:20:53 -03001786 if (vfd->v4l2_dev)
1787 pr_info("%s: ================== END STATUS ==================\n",
1788 vfd->v4l2_dev->name);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001789 break;
1790 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001791 case VIDIOC_DBG_G_REGISTER:
1792 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001793#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001794 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001795
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001796 if (!capable(CAP_SYS_ADMIN))
1797 ret = -EPERM;
1798 else
1799 ret = ops->vidioc_g_register(file, fh, p);
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001800#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001801 break;
1802 }
1803 case VIDIOC_DBG_S_REGISTER:
1804 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001805#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001806 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001807
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001808 if (!capable(CAP_SYS_ADMIN))
1809 ret = -EPERM;
1810 else
1811 ret = ops->vidioc_s_register(file, fh, p);
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001812#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001813 break;
1814 }
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001815 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001816 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001817 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001818
Hans Verkuil80b36e02009-02-07 11:00:02 -03001819 p->ident = V4L2_IDENT_NONE;
1820 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001821 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001822 if (!ret)
1823 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1824 break;
1825 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001826 case VIDIOC_S_HW_FREQ_SEEK:
1827 {
1828 struct v4l2_hw_freq_seek *p = arg;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001829 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001830
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001831 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1832 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001833 dbgarg(cmd,
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001834 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1835 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1836 if (p->type != type)
1837 ret = -EINVAL;
1838 else
1839 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
Hans Verkuila3998102008-07-21 02:57:38 -03001840 break;
1841 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001842 case VIDIOC_ENUM_FRAMESIZES:
1843 {
1844 struct v4l2_frmsizeenum *p = arg;
1845
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001846 ret = ops->vidioc_enum_framesizes(file, fh, p);
1847 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001848 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1849 p->index,
1850 (p->pixel_format & 0xff),
1851 (p->pixel_format >> 8) & 0xff,
1852 (p->pixel_format >> 16) & 0xff,
1853 (p->pixel_format >> 24) & 0xff,
1854 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001855 switch (p->type) {
1856 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001857 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001858 p->discrete.width, p->discrete.height);
1859 break;
1860 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001861 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001862 p->stepwise.min_width, p->stepwise.min_height,
1863 p->stepwise.step_width, p->stepwise.step_height,
1864 p->stepwise.max_width, p->stepwise.max_height);
1865 break;
1866 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001867 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001868 break;
1869 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001870 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001871 }
1872
1873 break;
1874 }
1875 case VIDIOC_ENUM_FRAMEINTERVALS:
1876 {
1877 struct v4l2_frmivalenum *p = arg;
1878
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001879 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1880 dbgarg(cmd,
1881 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1882 p->index, p->pixel_format,
1883 p->width, p->height, p->type);
1884 switch (p->type) {
1885 case V4L2_FRMIVAL_TYPE_DISCRETE:
1886 dbgarg2("fps=%d/%d\n",
1887 p->discrete.numerator,
1888 p->discrete.denominator);
1889 break;
1890 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001891 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1892 p->stepwise.min.numerator,
1893 p->stepwise.min.denominator,
1894 p->stepwise.max.numerator,
1895 p->stepwise.max.denominator,
1896 p->stepwise.step.numerator,
1897 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001898 break;
1899 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1900 dbgarg2("continuous\n");
1901 break;
1902 default:
1903 dbgarg2("- Unknown type!\n");
1904 }
1905 break;
1906 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001907 case VIDIOC_ENUM_DV_PRESETS:
1908 {
1909 struct v4l2_dv_enum_preset *p = arg;
1910
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001911 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1912 if (!ret)
1913 dbgarg(cmd,
1914 "index=%d, preset=%d, name=%s, width=%d,"
1915 " height=%d ",
1916 p->index, p->preset, p->name, p->width,
1917 p->height);
1918 break;
1919 }
1920 case VIDIOC_S_DV_PRESET:
1921 {
1922 struct v4l2_dv_preset *p = arg;
1923
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001924 dbgarg(cmd, "preset=%d\n", p->preset);
1925 ret = ops->vidioc_s_dv_preset(file, fh, p);
1926 break;
1927 }
1928 case VIDIOC_G_DV_PRESET:
1929 {
1930 struct v4l2_dv_preset *p = arg;
1931
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001932 ret = ops->vidioc_g_dv_preset(file, fh, p);
1933 if (!ret)
1934 dbgarg(cmd, "preset=%d\n", p->preset);
1935 break;
1936 }
1937 case VIDIOC_QUERY_DV_PRESET:
1938 {
1939 struct v4l2_dv_preset *p = arg;
1940
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001941 ret = ops->vidioc_query_dv_preset(file, fh, p);
1942 if (!ret)
1943 dbgarg(cmd, "preset=%d\n", p->preset);
1944 break;
1945 }
1946 case VIDIOC_S_DV_TIMINGS:
1947 {
1948 struct v4l2_dv_timings *p = arg;
1949
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001950 dbgtimings(vfd, p);
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001951 switch (p->type) {
1952 case V4L2_DV_BT_656_1120:
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001953 ret = ops->vidioc_s_dv_timings(file, fh, p);
1954 break;
1955 default:
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001956 ret = -EINVAL;
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001957 break;
1958 }
1959 break;
1960 }
1961 case VIDIOC_G_DV_TIMINGS:
1962 {
1963 struct v4l2_dv_timings *p = arg;
1964
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001965 ret = ops->vidioc_g_dv_timings(file, fh, p);
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001966 if (!ret)
1967 dbgtimings(vfd, p);
1968 break;
1969 }
1970 case VIDIOC_ENUM_DV_TIMINGS:
1971 {
1972 struct v4l2_enum_dv_timings *p = arg;
1973
1974 if (!ops->vidioc_enum_dv_timings)
1975 break;
1976
1977 ret = ops->vidioc_enum_dv_timings(file, fh, p);
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001978 if (!ret) {
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001979 dbgarg(cmd, "index=%d: ", p->index);
1980 dbgtimings(vfd, &p->timings);
1981 }
1982 break;
1983 }
1984 case VIDIOC_QUERY_DV_TIMINGS:
1985 {
1986 struct v4l2_dv_timings *p = arg;
1987
1988 if (!ops->vidioc_query_dv_timings)
1989 break;
1990
1991 ret = ops->vidioc_query_dv_timings(file, fh, p);
1992 if (!ret)
1993 dbgtimings(vfd, p);
1994 break;
1995 }
1996 case VIDIOC_DV_TIMINGS_CAP:
1997 {
1998 struct v4l2_dv_timings_cap *p = arg;
1999
2000 if (!ops->vidioc_dv_timings_cap)
2001 break;
2002
2003 ret = ops->vidioc_dv_timings_cap(file, fh, p);
2004 if (ret)
2005 break;
2006 switch (p->type) {
2007 case V4L2_DV_BT_656_1120:
2008 dbgarg(cmd,
2009 "type=%d, width=%u-%u, height=%u-%u, "
2010 "pixelclock=%llu-%llu, standards=%x, capabilities=%x ",
2011 p->type,
2012 p->bt.min_width, p->bt.max_width,
2013 p->bt.min_height, p->bt.max_height,
2014 p->bt.min_pixelclock, p->bt.max_pixelclock,
2015 p->bt.standards, p->bt.capabilities);
2016 break;
2017 default:
2018 dbgarg(cmd, "unknown type ");
2019 break;
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002020 }
2021 break;
2022 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002023 case VIDIOC_DQEVENT:
2024 {
2025 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002026
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002027 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2028 if (ret < 0) {
2029 dbgarg(cmd, "no pending events?");
2030 break;
2031 }
2032 dbgarg(cmd,
2033 "pending=%d, type=0x%8.8x, sequence=%d, "
2034 "timestamp=%lu.%9.9lu ",
2035 ev->pending, ev->type, ev->sequence,
2036 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2037 break;
2038 }
2039 case VIDIOC_SUBSCRIBE_EVENT:
2040 {
2041 struct v4l2_event_subscription *sub = arg;
2042
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002043 ret = ops->vidioc_subscribe_event(fh, sub);
2044 if (ret < 0) {
2045 dbgarg(cmd, "failed, ret=%ld", ret);
2046 break;
2047 }
2048 dbgarg(cmd, "type=0x%8.8x", sub->type);
2049 break;
2050 }
2051 case VIDIOC_UNSUBSCRIBE_EVENT:
2052 {
2053 struct v4l2_event_subscription *sub = arg;
2054
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002055 ret = ops->vidioc_unsubscribe_event(fh, sub);
2056 if (ret < 0) {
2057 dbgarg(cmd, "failed, ret=%ld", ret);
2058 break;
2059 }
2060 dbgarg(cmd, "type=0x%8.8x", sub->type);
2061 break;
2062 }
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002063 case VIDIOC_CREATE_BUFS:
2064 {
2065 struct v4l2_create_buffers *create = arg;
2066
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002067 ret = check_fmt(ops, create->format.type);
2068 if (ret)
2069 break;
2070
2071 ret = ops->vidioc_create_bufs(file, fh, create);
2072
2073 dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2074 break;
2075 }
2076 case VIDIOC_PREPARE_BUF:
2077 {
2078 struct v4l2_buffer *b = arg;
2079
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002080 ret = check_fmt(ops, b->type);
2081 if (ret)
2082 break;
2083
2084 ret = ops->vidioc_prepare_buf(file, fh, b);
2085
2086 dbgarg(cmd, "index=%d", b->index);
2087 break;
2088 }
Hans Verkuila3998102008-07-21 02:57:38 -03002089 default:
Hans Verkuila3998102008-07-21 02:57:38 -03002090 if (!ops->vidioc_default)
2091 break;
Hans Verkuil4b902fe2012-05-10 05:40:50 -03002092 ret = ops->vidioc_default(file, fh, use_fh_prio ?
2093 v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
2094 cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002095 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002096 } /* switch */
2097
2098 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2099 if (ret < 0) {
2100 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002101 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002102 }
2103 }
2104
2105 return ret;
2106}
2107
Trent Piepho19c96e42009-03-04 01:21:02 -03002108/* In some cases, only a few fields are used as input, i.e. when the app sets
2109 * "index" and then the driver fills in the rest of the structure for the thing
2110 * with that index. We only need to copy up the first non-input field. */
2111static unsigned long cmd_input_size(unsigned int cmd)
2112{
2113 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002114#define CMDINSIZE(cmd, type, field) \
2115 case VIDIOC_##cmd: \
2116 return offsetof(struct v4l2_##type, field) + \
2117 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002118
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002119 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002120 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2121 CMDINSIZE(G_FMT, format, type);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002122 CMDINSIZE(QUERYBUF, buffer, length);
Trent Piepho19c96e42009-03-04 01:21:02 -03002123 CMDINSIZE(G_PARM, streamparm, type);
2124 CMDINSIZE(ENUMSTD, standard, index);
2125 CMDINSIZE(ENUMINPUT, input, index);
2126 CMDINSIZE(G_CTRL, control, id);
2127 CMDINSIZE(G_TUNER, tuner, index);
2128 CMDINSIZE(QUERYCTRL, queryctrl, id);
2129 CMDINSIZE(QUERYMENU, querymenu, index);
2130 CMDINSIZE(ENUMOUTPUT, output, index);
2131 CMDINSIZE(G_MODULATOR, modulator, index);
2132 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2133 CMDINSIZE(CROPCAP, cropcap, type);
2134 CMDINSIZE(G_CROP, crop, type);
2135 CMDINSIZE(ENUMAUDIO, audio, index);
2136 CMDINSIZE(ENUMAUDOUT, audioout, index);
2137 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2138 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2139 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2140 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2141 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2142 default:
2143 return _IOC_SIZE(cmd);
2144 }
2145}
2146
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002147static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2148 void * __user *user_ptr, void ***kernel_ptr)
2149{
2150 int ret = 0;
2151
2152 switch (cmd) {
2153 case VIDIOC_QUERYBUF:
2154 case VIDIOC_QBUF:
2155 case VIDIOC_DQBUF: {
2156 struct v4l2_buffer *buf = parg;
2157
2158 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2159 if (buf->length > VIDEO_MAX_PLANES) {
2160 ret = -EINVAL;
2161 break;
2162 }
2163 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002164 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002165 *array_size = sizeof(struct v4l2_plane) * buf->length;
2166 ret = 1;
2167 }
2168 break;
2169 }
2170
2171 case VIDIOC_S_EXT_CTRLS:
2172 case VIDIOC_G_EXT_CTRLS:
2173 case VIDIOC_TRY_EXT_CTRLS: {
2174 struct v4l2_ext_controls *ctrls = parg;
2175
2176 if (ctrls->count != 0) {
Dan Carpenter6c061082012-01-05 02:27:57 -03002177 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2178 ret = -EINVAL;
2179 break;
2180 }
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002181 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002182 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002183 *array_size = sizeof(struct v4l2_ext_control)
2184 * ctrls->count;
2185 ret = 1;
2186 }
2187 break;
2188 }
2189 }
2190
2191 return ret;
2192}
2193
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002194long
2195video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2196 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002197{
2198 char sbuf[128];
2199 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002200 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002201 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002202 bool has_array_args;
2203 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002204 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002205 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002206
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002207 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002208 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002209 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2210 parg = sbuf;
2211 } else {
2212 /* too big to allocate from stack */
2213 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2214 if (NULL == mbuf)
2215 return -ENOMEM;
2216 parg = mbuf;
2217 }
2218
2219 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002220 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2221 unsigned long n = cmd_input_size(cmd);
2222
2223 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002224 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002225
2226 /* zero out anything we don't copy from userspace */
2227 if (n < _IOC_SIZE(cmd))
2228 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002229 } else {
2230 /* read-only ioctl */
2231 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002232 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002233 }
2234
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002235 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2236 if (err < 0)
2237 goto out;
2238 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002239
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002240 if (has_array_args) {
2241 /*
2242 * When adding new types of array args, make sure that the
2243 * parent argument to ioctl (which contains the pointer to the
2244 * array) fits into sbuf (so that mbuf will still remain
2245 * unused up to here).
2246 */
2247 mbuf = kmalloc(array_size, GFP_KERNEL);
2248 err = -ENOMEM;
2249 if (NULL == mbuf)
2250 goto out_array_args;
2251 err = -EFAULT;
2252 if (copy_from_user(mbuf, user_ptr, array_size))
2253 goto out_array_args;
2254 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002255 }
2256
2257 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002258 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002259 if (err == -ENOIOCTLCMD)
Hans Verkuil02bbb812012-02-08 08:09:36 -03002260 err = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002261
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002262 if (has_array_args) {
2263 *kernel_ptr = user_ptr;
2264 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002265 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002266 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002267 }
Hans Verkuil5d7758e2012-05-15 08:06:44 -03002268 /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid
2269 results that must be returned. */
2270 if (err < 0 && cmd != VIDIOC_QUERY_DV_TIMINGS)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002271 goto out;
2272
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002273out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002274 /* Copy results into user buffer */
2275 switch (_IOC_DIR(cmd)) {
2276 case _IOC_READ:
2277 case (_IOC_WRITE | _IOC_READ):
2278 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2279 err = -EFAULT;
2280 break;
2281 }
2282
2283out:
2284 kfree(mbuf);
2285 return err;
2286}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002287EXPORT_SYMBOL(video_usercopy);
2288
2289long video_ioctl2(struct file *file,
2290 unsigned int cmd, unsigned long arg)
2291{
2292 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2293}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002294EXPORT_SYMBOL(video_ioctl2);