1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Video capture interface for Linux version 2
5 * A generic framework to process V4L2 ioctl commands.
7 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
8 * Mauro Carvalho Chehab <mchehab@kernel.org> (version 2)
11 #include <linux/compat.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/version.h>
19 #include <linux/videodev2.h>
21 #include <media/v4l2-common.h>
22 #include <media/v4l2-ioctl.h>
23 #include <media/v4l2-ctrls.h>
24 #include <media/v4l2-fh.h>
25 #include <media/v4l2-event.h>
26 #include <media/v4l2-device.h>
27 #include <media/videobuf2-v4l2.h>
28 #include <media/v4l2-mc.h>
29 #include <media/v4l2-mem2mem.h>
31 #include <trace/events/v4l2.h>
33 /* Zero out the end of the struct pointed to by p. Everything after, but
34 * not including, the specified field is cleared. */
35 #define CLEAR_AFTER_FIELD(p, field) \
36 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
37 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
39 #define is_valid_ioctl(vfd, cmd) test_bit(_IOC_NR(cmd), (vfd)->valid_ioctls)
46 static const struct std_descr standards
[] = {
47 { V4L2_STD_NTSC
, "NTSC" },
48 { V4L2_STD_NTSC_M
, "NTSC-M" },
49 { V4L2_STD_NTSC_M_JP
, "NTSC-M-JP" },
50 { V4L2_STD_NTSC_M_KR
, "NTSC-M-KR" },
51 { V4L2_STD_NTSC_443
, "NTSC-443" },
52 { V4L2_STD_PAL
, "PAL" },
53 { V4L2_STD_PAL_BG
, "PAL-BG" },
54 { V4L2_STD_PAL_B
, "PAL-B" },
55 { V4L2_STD_PAL_B1
, "PAL-B1" },
56 { V4L2_STD_PAL_G
, "PAL-G" },
57 { V4L2_STD_PAL_H
, "PAL-H" },
58 { V4L2_STD_PAL_I
, "PAL-I" },
59 { V4L2_STD_PAL_DK
, "PAL-DK" },
60 { V4L2_STD_PAL_D
, "PAL-D" },
61 { V4L2_STD_PAL_D1
, "PAL-D1" },
62 { V4L2_STD_PAL_K
, "PAL-K" },
63 { V4L2_STD_PAL_M
, "PAL-M" },
64 { V4L2_STD_PAL_N
, "PAL-N" },
65 { V4L2_STD_PAL_Nc
, "PAL-Nc" },
66 { V4L2_STD_PAL_60
, "PAL-60" },
67 { V4L2_STD_SECAM
, "SECAM" },
68 { V4L2_STD_SECAM_B
, "SECAM-B" },
69 { V4L2_STD_SECAM_G
, "SECAM-G" },
70 { V4L2_STD_SECAM_H
, "SECAM-H" },
71 { V4L2_STD_SECAM_DK
, "SECAM-DK" },
72 { V4L2_STD_SECAM_D
, "SECAM-D" },
73 { V4L2_STD_SECAM_K
, "SECAM-K" },
74 { V4L2_STD_SECAM_K1
, "SECAM-K1" },
75 { V4L2_STD_SECAM_L
, "SECAM-L" },
76 { V4L2_STD_SECAM_LC
, "SECAM-Lc" },
80 /* video4linux standard ID conversion to standard name
82 const char *v4l2_norm_to_name(v4l2_std_id id
)
87 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
88 64 bit comparisons. So, on that architecture, with some gcc
89 variants, compilation fails. Currently, the max value is 30bit wide.
93 for (i
= 0; standards
[i
].std
; i
++)
94 if (myid
== standards
[i
].std
)
96 return standards
[i
].descr
;
98 EXPORT_SYMBOL(v4l2_norm_to_name
);
100 /* Returns frame period for the given standard */
101 void v4l2_video_std_frame_period(int id
, struct v4l2_fract
*frameperiod
)
103 if (id
& V4L2_STD_525_60
) {
104 frameperiod
->numerator
= 1001;
105 frameperiod
->denominator
= 30000;
107 frameperiod
->numerator
= 1;
108 frameperiod
->denominator
= 25;
111 EXPORT_SYMBOL(v4l2_video_std_frame_period
);
113 /* Fill in the fields of a v4l2_standard structure according to the
114 'id' and 'transmission' parameters. Returns negative on error. */
115 int v4l2_video_std_construct(struct v4l2_standard
*vs
,
116 int id
, const char *name
)
119 v4l2_video_std_frame_period(id
, &vs
->frameperiod
);
120 vs
->framelines
= (id
& V4L2_STD_525_60
) ? 525 : 625;
121 strscpy(vs
->name
, name
, sizeof(vs
->name
));
124 EXPORT_SYMBOL(v4l2_video_std_construct
);
126 /* Fill in the fields of a v4l2_standard structure according to the
127 * 'id' and 'vs->index' parameters. Returns negative on error. */
128 int v4l_video_std_enumstd(struct v4l2_standard
*vs
, v4l2_std_id id
)
130 v4l2_std_id curr_id
= 0;
131 unsigned int index
= vs
->index
, i
, j
= 0;
132 const char *descr
= "";
134 /* Return -ENODATA if the id for the current input
135 or output is 0, meaning that it doesn't support this API. */
139 /* Return norm array in a canonical way */
140 for (i
= 0; i
<= index
&& id
; i
++) {
141 /* last std value in the standards array is 0, so this
142 while always ends there since (id & 0) == 0. */
143 while ((id
& standards
[j
].std
) != standards
[j
].std
)
145 curr_id
= standards
[j
].std
;
146 descr
= standards
[j
].descr
;
150 if (curr_id
!= V4L2_STD_PAL
&&
151 curr_id
!= V4L2_STD_SECAM
&&
152 curr_id
!= V4L2_STD_NTSC
)
158 v4l2_video_std_construct(vs
, curr_id
, descr
);
162 /* ----------------------------------------------------------------- */
163 /* some arrays for pretty-printing debug messages of enum types */
165 const char *v4l2_field_names
[] = {
166 [V4L2_FIELD_ANY
] = "any",
167 [V4L2_FIELD_NONE
] = "none",
168 [V4L2_FIELD_TOP
] = "top",
169 [V4L2_FIELD_BOTTOM
] = "bottom",
170 [V4L2_FIELD_INTERLACED
] = "interlaced",
171 [V4L2_FIELD_SEQ_TB
] = "seq-tb",
172 [V4L2_FIELD_SEQ_BT
] = "seq-bt",
173 [V4L2_FIELD_ALTERNATE
] = "alternate",
174 [V4L2_FIELD_INTERLACED_TB
] = "interlaced-tb",
175 [V4L2_FIELD_INTERLACED_BT
] = "interlaced-bt",
177 EXPORT_SYMBOL(v4l2_field_names
);
179 const char *v4l2_type_names
[] = {
181 [V4L2_BUF_TYPE_VIDEO_CAPTURE
] = "vid-cap",
182 [V4L2_BUF_TYPE_VIDEO_OVERLAY
] = "vid-overlay",
183 [V4L2_BUF_TYPE_VIDEO_OUTPUT
] = "vid-out",
184 [V4L2_BUF_TYPE_VBI_CAPTURE
] = "vbi-cap",
185 [V4L2_BUF_TYPE_VBI_OUTPUT
] = "vbi-out",
186 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
] = "sliced-vbi-cap",
187 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
] = "sliced-vbi-out",
188 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
] = "vid-out-overlay",
189 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
] = "vid-cap-mplane",
190 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
] = "vid-out-mplane",
191 [V4L2_BUF_TYPE_SDR_CAPTURE
] = "sdr-cap",
192 [V4L2_BUF_TYPE_SDR_OUTPUT
] = "sdr-out",
193 [V4L2_BUF_TYPE_META_CAPTURE
] = "meta-cap",
194 [V4L2_BUF_TYPE_META_OUTPUT
] = "meta-out",
196 EXPORT_SYMBOL(v4l2_type_names
);
198 static const char *v4l2_memory_names
[] = {
199 [V4L2_MEMORY_MMAP
] = "mmap",
200 [V4L2_MEMORY_USERPTR
] = "userptr",
201 [V4L2_MEMORY_OVERLAY
] = "overlay",
202 [V4L2_MEMORY_DMABUF
] = "dmabuf",
205 #define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown")
207 /* ------------------------------------------------------------------ */
208 /* debug help functions */
210 static void v4l_print_querycap(const void *arg
, bool write_only
)
212 const struct v4l2_capability
*p
= arg
;
214 pr_cont("driver=%.*s, card=%.*s, bus=%.*s, version=0x%08x, capabilities=0x%08x, device_caps=0x%08x\n",
215 (int)sizeof(p
->driver
), p
->driver
,
216 (int)sizeof(p
->card
), p
->card
,
217 (int)sizeof(p
->bus_info
), p
->bus_info
,
218 p
->version
, p
->capabilities
, p
->device_caps
);
221 static void v4l_print_enuminput(const void *arg
, bool write_only
)
223 const struct v4l2_input
*p
= arg
;
225 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, tuner=%u, std=0x%08Lx, status=0x%x, capabilities=0x%x\n",
226 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->type
, p
->audioset
,
227 p
->tuner
, (unsigned long long)p
->std
, p
->status
,
231 static void v4l_print_enumoutput(const void *arg
, bool write_only
)
233 const struct v4l2_output
*p
= arg
;
235 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, modulator=%u, std=0x%08Lx, capabilities=0x%x\n",
236 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->type
, p
->audioset
,
237 p
->modulator
, (unsigned long long)p
->std
, p
->capabilities
);
240 static void v4l_print_audio(const void *arg
, bool write_only
)
242 const struct v4l2_audio
*p
= arg
;
245 pr_cont("index=%u, mode=0x%x\n", p
->index
, p
->mode
);
247 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
248 p
->index
, (int)sizeof(p
->name
), p
->name
,
249 p
->capability
, p
->mode
);
252 static void v4l_print_audioout(const void *arg
, bool write_only
)
254 const struct v4l2_audioout
*p
= arg
;
257 pr_cont("index=%u\n", p
->index
);
259 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
260 p
->index
, (int)sizeof(p
->name
), p
->name
,
261 p
->capability
, p
->mode
);
264 static void v4l_print_fmtdesc(const void *arg
, bool write_only
)
266 const struct v4l2_fmtdesc
*p
= arg
;
268 pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, mbus_code=0x%04x, description='%.*s'\n",
269 p
->index
, prt_names(p
->type
, v4l2_type_names
),
270 p
->flags
, (p
->pixelformat
& 0xff),
271 (p
->pixelformat
>> 8) & 0xff,
272 (p
->pixelformat
>> 16) & 0xff,
273 (p
->pixelformat
>> 24) & 0xff,
275 (int)sizeof(p
->description
), p
->description
);
278 static void v4l_print_format(const void *arg
, bool write_only
)
280 const struct v4l2_format
*p
= arg
;
281 const struct v4l2_pix_format
*pix
;
282 const struct v4l2_pix_format_mplane
*mp
;
283 const struct v4l2_vbi_format
*vbi
;
284 const struct v4l2_sliced_vbi_format
*sliced
;
285 const struct v4l2_window
*win
;
286 const struct v4l2_sdr_format
*sdr
;
287 const struct v4l2_meta_format
*meta
;
291 pr_cont("type=%s", prt_names(p
->type
, v4l2_type_names
));
293 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
294 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
296 pr_cont(", width=%u, height=%u, pixelformat=%c%c%c%c, field=%s, bytesperline=%u, sizeimage=%u, colorspace=%d, flags=0x%x, ycbcr_enc=%u, quantization=%u, xfer_func=%u\n",
297 pix
->width
, pix
->height
,
298 (pix
->pixelformat
& 0xff),
299 (pix
->pixelformat
>> 8) & 0xff,
300 (pix
->pixelformat
>> 16) & 0xff,
301 (pix
->pixelformat
>> 24) & 0xff,
302 prt_names(pix
->field
, v4l2_field_names
),
303 pix
->bytesperline
, pix
->sizeimage
,
304 pix
->colorspace
, pix
->flags
, pix
->ycbcr_enc
,
305 pix
->quantization
, pix
->xfer_func
);
307 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
308 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
310 pr_cont(", width=%u, height=%u, format=%c%c%c%c, field=%s, colorspace=%d, num_planes=%u, flags=0x%x, ycbcr_enc=%u, quantization=%u, xfer_func=%u\n",
311 mp
->width
, mp
->height
,
312 (mp
->pixelformat
& 0xff),
313 (mp
->pixelformat
>> 8) & 0xff,
314 (mp
->pixelformat
>> 16) & 0xff,
315 (mp
->pixelformat
>> 24) & 0xff,
316 prt_names(mp
->field
, v4l2_field_names
),
317 mp
->colorspace
, mp
->num_planes
, mp
->flags
,
318 mp
->ycbcr_enc
, mp
->quantization
, mp
->xfer_func
);
319 planes
= min_t(u32
, mp
->num_planes
, VIDEO_MAX_PLANES
);
320 for (i
= 0; i
< planes
; i
++)
321 printk(KERN_DEBUG
"plane %u: bytesperline=%u sizeimage=%u\n", i
,
322 mp
->plane_fmt
[i
].bytesperline
,
323 mp
->plane_fmt
[i
].sizeimage
);
325 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
326 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
328 /* Note: we can't print the clip list here since the clips
329 * pointer is a userspace pointer, not a kernelspace
331 pr_cont(", wxh=%dx%d, x,y=%d,%d, field=%s, chromakey=0x%08x, clipcount=%u, clips=%p, bitmap=%p, global_alpha=0x%02x\n",
332 win
->w
.width
, win
->w
.height
, win
->w
.left
, win
->w
.top
,
333 prt_names(win
->field
, v4l2_field_names
),
334 win
->chromakey
, win
->clipcount
, win
->clips
,
335 win
->bitmap
, win
->global_alpha
);
337 case V4L2_BUF_TYPE_VBI_CAPTURE
:
338 case V4L2_BUF_TYPE_VBI_OUTPUT
:
340 pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, sample_format=%c%c%c%c, start=%u,%u, count=%u,%u\n",
341 vbi
->sampling_rate
, vbi
->offset
,
342 vbi
->samples_per_line
,
343 (vbi
->sample_format
& 0xff),
344 (vbi
->sample_format
>> 8) & 0xff,
345 (vbi
->sample_format
>> 16) & 0xff,
346 (vbi
->sample_format
>> 24) & 0xff,
347 vbi
->start
[0], vbi
->start
[1],
348 vbi
->count
[0], vbi
->count
[1]);
350 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
351 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
352 sliced
= &p
->fmt
.sliced
;
353 pr_cont(", service_set=0x%08x, io_size=%d\n",
354 sliced
->service_set
, sliced
->io_size
);
355 for (i
= 0; i
< 24; i
++)
356 printk(KERN_DEBUG
"line[%02u]=0x%04x, 0x%04x\n", i
,
357 sliced
->service_lines
[0][i
],
358 sliced
->service_lines
[1][i
]);
360 case V4L2_BUF_TYPE_SDR_CAPTURE
:
361 case V4L2_BUF_TYPE_SDR_OUTPUT
:
363 pr_cont(", pixelformat=%c%c%c%c\n",
364 (sdr
->pixelformat
>> 0) & 0xff,
365 (sdr
->pixelformat
>> 8) & 0xff,
366 (sdr
->pixelformat
>> 16) & 0xff,
367 (sdr
->pixelformat
>> 24) & 0xff);
369 case V4L2_BUF_TYPE_META_CAPTURE
:
370 case V4L2_BUF_TYPE_META_OUTPUT
:
372 pr_cont(", dataformat=%c%c%c%c, buffersize=%u\n",
373 (meta
->dataformat
>> 0) & 0xff,
374 (meta
->dataformat
>> 8) & 0xff,
375 (meta
->dataformat
>> 16) & 0xff,
376 (meta
->dataformat
>> 24) & 0xff,
382 static void v4l_print_framebuffer(const void *arg
, bool write_only
)
384 const struct v4l2_framebuffer
*p
= arg
;
386 pr_cont("capability=0x%x, flags=0x%x, base=0x%p, width=%u, height=%u, pixelformat=%c%c%c%c, bytesperline=%u, sizeimage=%u, colorspace=%d\n",
387 p
->capability
, p
->flags
, p
->base
,
388 p
->fmt
.width
, p
->fmt
.height
,
389 (p
->fmt
.pixelformat
& 0xff),
390 (p
->fmt
.pixelformat
>> 8) & 0xff,
391 (p
->fmt
.pixelformat
>> 16) & 0xff,
392 (p
->fmt
.pixelformat
>> 24) & 0xff,
393 p
->fmt
.bytesperline
, p
->fmt
.sizeimage
,
397 static void v4l_print_buftype(const void *arg
, bool write_only
)
399 pr_cont("type=%s\n", prt_names(*(u32
*)arg
, v4l2_type_names
));
402 static void v4l_print_modulator(const void *arg
, bool write_only
)
404 const struct v4l2_modulator
*p
= arg
;
407 pr_cont("index=%u, txsubchans=0x%x\n", p
->index
, p
->txsubchans
);
409 pr_cont("index=%u, name=%.*s, capability=0x%x, rangelow=%u, rangehigh=%u, txsubchans=0x%x\n",
410 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->capability
,
411 p
->rangelow
, p
->rangehigh
, p
->txsubchans
);
414 static void v4l_print_tuner(const void *arg
, bool write_only
)
416 const struct v4l2_tuner
*p
= arg
;
419 pr_cont("index=%u, audmode=%u\n", p
->index
, p
->audmode
);
421 pr_cont("index=%u, name=%.*s, type=%u, capability=0x%x, rangelow=%u, rangehigh=%u, signal=%u, afc=%d, rxsubchans=0x%x, audmode=%u\n",
422 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->type
,
423 p
->capability
, p
->rangelow
,
424 p
->rangehigh
, p
->signal
, p
->afc
,
425 p
->rxsubchans
, p
->audmode
);
428 static void v4l_print_frequency(const void *arg
, bool write_only
)
430 const struct v4l2_frequency
*p
= arg
;
432 pr_cont("tuner=%u, type=%u, frequency=%u\n",
433 p
->tuner
, p
->type
, p
->frequency
);
436 static void v4l_print_standard(const void *arg
, bool write_only
)
438 const struct v4l2_standard
*p
= arg
;
440 pr_cont("index=%u, id=0x%Lx, name=%.*s, fps=%u/%u, framelines=%u\n",
442 (unsigned long long)p
->id
, (int)sizeof(p
->name
), p
->name
,
443 p
->frameperiod
.numerator
,
444 p
->frameperiod
.denominator
,
448 static void v4l_print_std(const void *arg
, bool write_only
)
450 pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg
);
453 static void v4l_print_hw_freq_seek(const void *arg
, bool write_only
)
455 const struct v4l2_hw_freq_seek
*p
= arg
;
457 pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u, rangelow=%u, rangehigh=%u\n",
458 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
, p
->spacing
,
459 p
->rangelow
, p
->rangehigh
);
462 static void v4l_print_requestbuffers(const void *arg
, bool write_only
)
464 const struct v4l2_requestbuffers
*p
= arg
;
466 pr_cont("count=%d, type=%s, memory=%s\n",
468 prt_names(p
->type
, v4l2_type_names
),
469 prt_names(p
->memory
, v4l2_memory_names
));
472 static void v4l_print_buffer(const void *arg
, bool write_only
)
474 const struct v4l2_buffer
*p
= arg
;
475 const struct v4l2_timecode
*tc
= &p
->timecode
;
476 const struct v4l2_plane
*plane
;
479 pr_cont("%02d:%02d:%02d.%09ld index=%d, type=%s, request_fd=%d, flags=0x%08x, field=%s, sequence=%d, memory=%s",
480 (int)p
->timestamp
.tv_sec
/ 3600,
481 ((int)p
->timestamp
.tv_sec
/ 60) % 60,
482 ((int)p
->timestamp
.tv_sec
% 60),
483 (long)p
->timestamp
.tv_usec
,
485 prt_names(p
->type
, v4l2_type_names
), p
->request_fd
,
486 p
->flags
, prt_names(p
->field
, v4l2_field_names
),
487 p
->sequence
, prt_names(p
->memory
, v4l2_memory_names
));
489 if (V4L2_TYPE_IS_MULTIPLANAR(p
->type
) && p
->m
.planes
) {
491 for (i
= 0; i
< p
->length
; ++i
) {
492 plane
= &p
->m
.planes
[i
];
494 "plane %d: bytesused=%d, data_offset=0x%08x, offset/userptr=0x%lx, length=%d\n",
495 i
, plane
->bytesused
, plane
->data_offset
,
496 plane
->m
.userptr
, plane
->length
);
499 pr_cont(", bytesused=%d, offset/userptr=0x%lx, length=%d\n",
500 p
->bytesused
, p
->m
.userptr
, p
->length
);
503 printk(KERN_DEBUG
"timecode=%02d:%02d:%02d type=%d, flags=0x%08x, frames=%d, userbits=0x%08x\n",
504 tc
->hours
, tc
->minutes
, tc
->seconds
,
505 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
508 static void v4l_print_exportbuffer(const void *arg
, bool write_only
)
510 const struct v4l2_exportbuffer
*p
= arg
;
512 pr_cont("fd=%d, type=%s, index=%u, plane=%u, flags=0x%08x\n",
513 p
->fd
, prt_names(p
->type
, v4l2_type_names
),
514 p
->index
, p
->plane
, p
->flags
);
517 static void v4l_print_create_buffers(const void *arg
, bool write_only
)
519 const struct v4l2_create_buffers
*p
= arg
;
521 pr_cont("index=%d, count=%d, memory=%s, ",
523 prt_names(p
->memory
, v4l2_memory_names
));
524 v4l_print_format(&p
->format
, write_only
);
527 static void v4l_print_streamparm(const void *arg
, bool write_only
)
529 const struct v4l2_streamparm
*p
= arg
;
531 pr_cont("type=%s", prt_names(p
->type
, v4l2_type_names
));
533 if (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
||
534 p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
535 const struct v4l2_captureparm
*c
= &p
->parm
.capture
;
537 pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, extendedmode=%d, readbuffers=%d\n",
538 c
->capability
, c
->capturemode
,
539 c
->timeperframe
.numerator
, c
->timeperframe
.denominator
,
540 c
->extendedmode
, c
->readbuffers
);
541 } else if (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
||
542 p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
543 const struct v4l2_outputparm
*c
= &p
->parm
.output
;
545 pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, extendedmode=%d, writebuffers=%d\n",
546 c
->capability
, c
->outputmode
,
547 c
->timeperframe
.numerator
, c
->timeperframe
.denominator
,
548 c
->extendedmode
, c
->writebuffers
);
554 static void v4l_print_queryctrl(const void *arg
, bool write_only
)
556 const struct v4l2_queryctrl
*p
= arg
;
558 pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%d/%d, step=%d, default=%d, flags=0x%08x\n",
559 p
->id
, p
->type
, (int)sizeof(p
->name
), p
->name
,
560 p
->minimum
, p
->maximum
,
561 p
->step
, p
->default_value
, p
->flags
);
564 static void v4l_print_query_ext_ctrl(const void *arg
, bool write_only
)
566 const struct v4l2_query_ext_ctrl
*p
= arg
;
568 pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%lld/%lld, step=%lld, default=%lld, flags=0x%08x, elem_size=%u, elems=%u, nr_of_dims=%u, dims=%u,%u,%u,%u\n",
569 p
->id
, p
->type
, (int)sizeof(p
->name
), p
->name
,
570 p
->minimum
, p
->maximum
,
571 p
->step
, p
->default_value
, p
->flags
,
572 p
->elem_size
, p
->elems
, p
->nr_of_dims
,
573 p
->dims
[0], p
->dims
[1], p
->dims
[2], p
->dims
[3]);
576 static void v4l_print_querymenu(const void *arg
, bool write_only
)
578 const struct v4l2_querymenu
*p
= arg
;
580 pr_cont("id=0x%x, index=%d\n", p
->id
, p
->index
);
583 static void v4l_print_control(const void *arg
, bool write_only
)
585 const struct v4l2_control
*p
= arg
;
586 const char *name
= v4l2_ctrl_get_name(p
->id
);
589 pr_cont("name=%s, ", name
);
590 pr_cont("id=0x%x, value=%d\n", p
->id
, p
->value
);
593 static void v4l_print_ext_controls(const void *arg
, bool write_only
)
595 const struct v4l2_ext_controls
*p
= arg
;
598 pr_cont("which=0x%x, count=%d, error_idx=%d, request_fd=%d",
599 p
->which
, p
->count
, p
->error_idx
, p
->request_fd
);
600 for (i
= 0; i
< p
->count
; i
++) {
601 unsigned int id
= p
->controls
[i
].id
;
602 const char *name
= v4l2_ctrl_get_name(id
);
605 pr_cont(", name=%s", name
);
606 if (!p
->controls
[i
].size
)
607 pr_cont(", id/val=0x%x/0x%x", id
, p
->controls
[i
].value
);
609 pr_cont(", id/size=0x%x/%u", id
, p
->controls
[i
].size
);
614 static void v4l_print_cropcap(const void *arg
, bool write_only
)
616 const struct v4l2_cropcap
*p
= arg
;
618 pr_cont("type=%s, bounds wxh=%dx%d, x,y=%d,%d, defrect wxh=%dx%d, x,y=%d,%d, pixelaspect %d/%d\n",
619 prt_names(p
->type
, v4l2_type_names
),
620 p
->bounds
.width
, p
->bounds
.height
,
621 p
->bounds
.left
, p
->bounds
.top
,
622 p
->defrect
.width
, p
->defrect
.height
,
623 p
->defrect
.left
, p
->defrect
.top
,
624 p
->pixelaspect
.numerator
, p
->pixelaspect
.denominator
);
627 static void v4l_print_crop(const void *arg
, bool write_only
)
629 const struct v4l2_crop
*p
= arg
;
631 pr_cont("type=%s, wxh=%dx%d, x,y=%d,%d\n",
632 prt_names(p
->type
, v4l2_type_names
),
633 p
->c
.width
, p
->c
.height
,
634 p
->c
.left
, p
->c
.top
);
637 static void v4l_print_selection(const void *arg
, bool write_only
)
639 const struct v4l2_selection
*p
= arg
;
641 pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
642 prt_names(p
->type
, v4l2_type_names
),
644 p
->r
.width
, p
->r
.height
, p
->r
.left
, p
->r
.top
);
647 static void v4l_print_jpegcompression(const void *arg
, bool write_only
)
649 const struct v4l2_jpegcompression
*p
= arg
;
651 pr_cont("quality=%d, APPn=%d, APP_len=%d, COM_len=%d, jpeg_markers=0x%x\n",
652 p
->quality
, p
->APPn
, p
->APP_len
,
653 p
->COM_len
, p
->jpeg_markers
);
656 static void v4l_print_enc_idx(const void *arg
, bool write_only
)
658 const struct v4l2_enc_idx
*p
= arg
;
660 pr_cont("entries=%d, entries_cap=%d\n",
661 p
->entries
, p
->entries_cap
);
664 static void v4l_print_encoder_cmd(const void *arg
, bool write_only
)
666 const struct v4l2_encoder_cmd
*p
= arg
;
668 pr_cont("cmd=%d, flags=0x%x\n",
672 static void v4l_print_decoder_cmd(const void *arg
, bool write_only
)
674 const struct v4l2_decoder_cmd
*p
= arg
;
676 pr_cont("cmd=%d, flags=0x%x\n", p
->cmd
, p
->flags
);
678 if (p
->cmd
== V4L2_DEC_CMD_START
)
679 pr_info("speed=%d, format=%u\n",
680 p
->start
.speed
, p
->start
.format
);
681 else if (p
->cmd
== V4L2_DEC_CMD_STOP
)
682 pr_info("pts=%llu\n", p
->stop
.pts
);
685 static void v4l_print_dbg_chip_info(const void *arg
, bool write_only
)
687 const struct v4l2_dbg_chip_info
*p
= arg
;
689 pr_cont("type=%u, ", p
->match
.type
);
690 if (p
->match
.type
== V4L2_CHIP_MATCH_I2C_DRIVER
)
691 pr_cont("name=%.*s, ",
692 (int)sizeof(p
->match
.name
), p
->match
.name
);
694 pr_cont("addr=%u, ", p
->match
.addr
);
695 pr_cont("name=%.*s\n", (int)sizeof(p
->name
), p
->name
);
698 static void v4l_print_dbg_register(const void *arg
, bool write_only
)
700 const struct v4l2_dbg_register
*p
= arg
;
702 pr_cont("type=%u, ", p
->match
.type
);
703 if (p
->match
.type
== V4L2_CHIP_MATCH_I2C_DRIVER
)
704 pr_cont("name=%.*s, ",
705 (int)sizeof(p
->match
.name
), p
->match
.name
);
707 pr_cont("addr=%u, ", p
->match
.addr
);
708 pr_cont("reg=0x%llx, val=0x%llx\n",
712 static void v4l_print_dv_timings(const void *arg
, bool write_only
)
714 const struct v4l2_dv_timings
*p
= arg
;
717 case V4L2_DV_BT_656_1120
:
718 pr_cont("type=bt-656/1120, interlaced=%u, pixelclock=%llu, width=%u, height=%u, polarities=0x%x, hfrontporch=%u, hsync=%u, hbackporch=%u, vfrontporch=%u, vsync=%u, vbackporch=%u, il_vfrontporch=%u, il_vsync=%u, il_vbackporch=%u, standards=0x%x, flags=0x%x\n",
719 p
->bt
.interlaced
, p
->bt
.pixelclock
,
720 p
->bt
.width
, p
->bt
.height
,
721 p
->bt
.polarities
, p
->bt
.hfrontporch
,
722 p
->bt
.hsync
, p
->bt
.hbackporch
,
723 p
->bt
.vfrontporch
, p
->bt
.vsync
,
724 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
725 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
,
726 p
->bt
.standards
, p
->bt
.flags
);
729 pr_cont("type=%d\n", p
->type
);
734 static void v4l_print_enum_dv_timings(const void *arg
, bool write_only
)
736 const struct v4l2_enum_dv_timings
*p
= arg
;
738 pr_cont("index=%u, ", p
->index
);
739 v4l_print_dv_timings(&p
->timings
, write_only
);
742 static void v4l_print_dv_timings_cap(const void *arg
, bool write_only
)
744 const struct v4l2_dv_timings_cap
*p
= arg
;
747 case V4L2_DV_BT_656_1120
:
748 pr_cont("type=bt-656/1120, width=%u-%u, height=%u-%u, pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n",
749 p
->bt
.min_width
, p
->bt
.max_width
,
750 p
->bt
.min_height
, p
->bt
.max_height
,
751 p
->bt
.min_pixelclock
, p
->bt
.max_pixelclock
,
752 p
->bt
.standards
, p
->bt
.capabilities
);
755 pr_cont("type=%u\n", p
->type
);
760 static void v4l_print_frmsizeenum(const void *arg
, bool write_only
)
762 const struct v4l2_frmsizeenum
*p
= arg
;
764 pr_cont("index=%u, pixelformat=%c%c%c%c, type=%u",
766 (p
->pixel_format
& 0xff),
767 (p
->pixel_format
>> 8) & 0xff,
768 (p
->pixel_format
>> 16) & 0xff,
769 (p
->pixel_format
>> 24) & 0xff,
772 case V4L2_FRMSIZE_TYPE_DISCRETE
:
773 pr_cont(", wxh=%ux%u\n",
774 p
->discrete
.width
, p
->discrete
.height
);
776 case V4L2_FRMSIZE_TYPE_STEPWISE
:
777 pr_cont(", min=%ux%u, max=%ux%u, step=%ux%u\n",
778 p
->stepwise
.min_width
,
779 p
->stepwise
.min_height
,
780 p
->stepwise
.max_width
,
781 p
->stepwise
.max_height
,
782 p
->stepwise
.step_width
,
783 p
->stepwise
.step_height
);
785 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
792 static void v4l_print_frmivalenum(const void *arg
, bool write_only
)
794 const struct v4l2_frmivalenum
*p
= arg
;
796 pr_cont("index=%u, pixelformat=%c%c%c%c, wxh=%ux%u, type=%u",
798 (p
->pixel_format
& 0xff),
799 (p
->pixel_format
>> 8) & 0xff,
800 (p
->pixel_format
>> 16) & 0xff,
801 (p
->pixel_format
>> 24) & 0xff,
802 p
->width
, p
->height
, p
->type
);
804 case V4L2_FRMIVAL_TYPE_DISCRETE
:
805 pr_cont(", fps=%d/%d\n",
806 p
->discrete
.numerator
,
807 p
->discrete
.denominator
);
809 case V4L2_FRMIVAL_TYPE_STEPWISE
:
810 pr_cont(", min=%d/%d, max=%d/%d, step=%d/%d\n",
811 p
->stepwise
.min
.numerator
,
812 p
->stepwise
.min
.denominator
,
813 p
->stepwise
.max
.numerator
,
814 p
->stepwise
.max
.denominator
,
815 p
->stepwise
.step
.numerator
,
816 p
->stepwise
.step
.denominator
);
818 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
825 static void v4l_print_event(const void *arg
, bool write_only
)
827 const struct v4l2_event
*p
= arg
;
828 const struct v4l2_event_ctrl
*c
;
830 pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, timestamp=%llu.%9.9llu\n",
831 p
->type
, p
->pending
, p
->sequence
, p
->id
,
832 p
->timestamp
.tv_sec
, p
->timestamp
.tv_nsec
);
834 case V4L2_EVENT_VSYNC
:
835 printk(KERN_DEBUG
"field=%s\n",
836 prt_names(p
->u
.vsync
.field
, v4l2_field_names
));
838 case V4L2_EVENT_CTRL
:
840 printk(KERN_DEBUG
"changes=0x%x, type=%u, ",
841 c
->changes
, c
->type
);
842 if (c
->type
== V4L2_CTRL_TYPE_INTEGER64
)
843 pr_cont("value64=%lld, ", c
->value64
);
845 pr_cont("value=%d, ", c
->value
);
846 pr_cont("flags=0x%x, minimum=%d, maximum=%d, step=%d, default_value=%d\n",
847 c
->flags
, c
->minimum
, c
->maximum
,
848 c
->step
, c
->default_value
);
850 case V4L2_EVENT_FRAME_SYNC
:
851 pr_cont("frame_sequence=%u\n",
852 p
->u
.frame_sync
.frame_sequence
);
857 static void v4l_print_event_subscription(const void *arg
, bool write_only
)
859 const struct v4l2_event_subscription
*p
= arg
;
861 pr_cont("type=0x%x, id=0x%x, flags=0x%x\n",
862 p
->type
, p
->id
, p
->flags
);
865 static void v4l_print_sliced_vbi_cap(const void *arg
, bool write_only
)
867 const struct v4l2_sliced_vbi_cap
*p
= arg
;
870 pr_cont("type=%s, service_set=0x%08x\n",
871 prt_names(p
->type
, v4l2_type_names
), p
->service_set
);
872 for (i
= 0; i
< 24; i
++)
873 printk(KERN_DEBUG
"line[%02u]=0x%04x, 0x%04x\n", i
,
874 p
->service_lines
[0][i
],
875 p
->service_lines
[1][i
]);
878 static void v4l_print_freq_band(const void *arg
, bool write_only
)
880 const struct v4l2_frequency_band
*p
= arg
;
882 pr_cont("tuner=%u, type=%u, index=%u, capability=0x%x, rangelow=%u, rangehigh=%u, modulation=0x%x\n",
883 p
->tuner
, p
->type
, p
->index
,
884 p
->capability
, p
->rangelow
,
885 p
->rangehigh
, p
->modulation
);
888 static void v4l_print_edid(const void *arg
, bool write_only
)
890 const struct v4l2_edid
*p
= arg
;
892 pr_cont("pad=%u, start_block=%u, blocks=%u\n",
893 p
->pad
, p
->start_block
, p
->blocks
);
896 static void v4l_print_u32(const void *arg
, bool write_only
)
898 pr_cont("value=%u\n", *(const u32
*)arg
);
901 static void v4l_print_newline(const void *arg
, bool write_only
)
906 static void v4l_print_default(const void *arg
, bool write_only
)
908 pr_cont("driver-specific ioctl\n");
911 static int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
915 /* zero the reserved fields */
917 for (i
= 0; i
< c
->count
; i
++)
918 c
->controls
[i
].reserved2
[0] = 0;
920 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
921 when using extended controls.
922 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
923 is it allowed for backwards compatibility.
925 if (!allow_priv
&& c
->which
== V4L2_CID_PRIVATE_BASE
)
929 /* Check that all controls are from the same control class. */
930 for (i
= 0; i
< c
->count
; i
++) {
931 if (V4L2_CTRL_ID2WHICH(c
->controls
[i
].id
) != c
->which
) {
939 static int check_fmt(struct file
*file
, enum v4l2_buf_type type
)
941 const u32 vid_caps
= V4L2_CAP_VIDEO_CAPTURE
|
942 V4L2_CAP_VIDEO_CAPTURE_MPLANE
|
943 V4L2_CAP_VIDEO_OUTPUT
|
944 V4L2_CAP_VIDEO_OUTPUT_MPLANE
|
945 V4L2_CAP_VIDEO_M2M
| V4L2_CAP_VIDEO_M2M_MPLANE
;
946 const u32 meta_caps
= V4L2_CAP_META_CAPTURE
|
947 V4L2_CAP_META_OUTPUT
;
948 struct video_device
*vfd
= video_devdata(file
);
949 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
950 bool is_vid
= vfd
->vfl_type
== VFL_TYPE_VIDEO
&&
951 (vfd
->device_caps
& vid_caps
);
952 bool is_vbi
= vfd
->vfl_type
== VFL_TYPE_VBI
;
953 bool is_sdr
= vfd
->vfl_type
== VFL_TYPE_SDR
;
954 bool is_tch
= vfd
->vfl_type
== VFL_TYPE_TOUCH
;
955 bool is_meta
= vfd
->vfl_type
== VFL_TYPE_VIDEO
&&
956 (vfd
->device_caps
& meta_caps
);
957 bool is_rx
= vfd
->vfl_dir
!= VFL_DIR_TX
;
958 bool is_tx
= vfd
->vfl_dir
!= VFL_DIR_RX
;
964 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
965 if ((is_vid
|| is_tch
) && is_rx
&&
966 (ops
->vidioc_g_fmt_vid_cap
|| ops
->vidioc_g_fmt_vid_cap_mplane
))
969 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
970 if ((is_vid
|| is_tch
) && is_rx
&& ops
->vidioc_g_fmt_vid_cap_mplane
)
973 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
974 if (is_vid
&& is_rx
&& ops
->vidioc_g_fmt_vid_overlay
)
977 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
978 if (is_vid
&& is_tx
&&
979 (ops
->vidioc_g_fmt_vid_out
|| ops
->vidioc_g_fmt_vid_out_mplane
))
982 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
983 if (is_vid
&& is_tx
&& ops
->vidioc_g_fmt_vid_out_mplane
)
986 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
987 if (is_vid
&& is_tx
&& ops
->vidioc_g_fmt_vid_out_overlay
)
990 case V4L2_BUF_TYPE_VBI_CAPTURE
:
991 if (is_vbi
&& is_rx
&& ops
->vidioc_g_fmt_vbi_cap
)
994 case V4L2_BUF_TYPE_VBI_OUTPUT
:
995 if (is_vbi
&& is_tx
&& ops
->vidioc_g_fmt_vbi_out
)
998 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
999 if (is_vbi
&& is_rx
&& ops
->vidioc_g_fmt_sliced_vbi_cap
)
1002 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1003 if (is_vbi
&& is_tx
&& ops
->vidioc_g_fmt_sliced_vbi_out
)
1006 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1007 if (is_sdr
&& is_rx
&& ops
->vidioc_g_fmt_sdr_cap
)
1010 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1011 if (is_sdr
&& is_tx
&& ops
->vidioc_g_fmt_sdr_out
)
1014 case V4L2_BUF_TYPE_META_CAPTURE
:
1015 if (is_meta
&& is_rx
&& ops
->vidioc_g_fmt_meta_cap
)
1018 case V4L2_BUF_TYPE_META_OUTPUT
:
1019 if (is_meta
&& is_tx
&& ops
->vidioc_g_fmt_meta_out
)
1028 static void v4l_sanitize_format(struct v4l2_format
*fmt
)
1030 unsigned int offset
;
1032 /* Make sure num_planes is not bogus */
1033 if (fmt
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
1034 fmt
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
1035 fmt
->fmt
.pix_mp
.num_planes
= min_t(u32
, fmt
->fmt
.pix_mp
.num_planes
,
1039 * The v4l2_pix_format structure has been extended with fields that were
1040 * not previously required to be set to zero by applications. The priv
1041 * field, when set to a magic value, indicates the the extended fields
1042 * are valid. Otherwise they will contain undefined values. To simplify
1043 * the API towards drivers zero the extended fields and set the priv
1044 * field to the magic value when the extended pixel format structure
1045 * isn't used by applications.
1048 if (fmt
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
1049 fmt
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1052 if (fmt
->fmt
.pix
.priv
== V4L2_PIX_FMT_PRIV_MAGIC
)
1055 fmt
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1057 offset
= offsetof(struct v4l2_pix_format
, priv
)
1058 + sizeof(fmt
->fmt
.pix
.priv
);
1059 memset(((void *)&fmt
->fmt
.pix
) + offset
, 0,
1060 sizeof(fmt
->fmt
.pix
) - offset
);
1063 static int v4l_querycap(const struct v4l2_ioctl_ops
*ops
,
1064 struct file
*file
, void *fh
, void *arg
)
1066 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
1067 struct video_device
*vfd
= video_devdata(file
);
1070 cap
->version
= LINUX_VERSION_CODE
;
1071 cap
->device_caps
= vfd
->device_caps
;
1072 cap
->capabilities
= vfd
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
1074 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
1077 * Drivers must not change device_caps, so check for this and
1078 * warn if this happened.
1080 WARN_ON(cap
->device_caps
!= vfd
->device_caps
);
1082 * Check that capabilities is a superset of
1083 * vfd->device_caps | V4L2_CAP_DEVICE_CAPS
1085 WARN_ON((cap
->capabilities
&
1086 (vfd
->device_caps
| V4L2_CAP_DEVICE_CAPS
)) !=
1087 (vfd
->device_caps
| V4L2_CAP_DEVICE_CAPS
));
1088 cap
->capabilities
|= V4L2_CAP_EXT_PIX_FORMAT
;
1089 cap
->device_caps
|= V4L2_CAP_EXT_PIX_FORMAT
;
1094 static int v4l_g_input(const struct v4l2_ioctl_ops
*ops
,
1095 struct file
*file
, void *fh
, void *arg
)
1097 struct video_device
*vfd
= video_devdata(file
);
1099 if (vfd
->device_caps
& V4L2_CAP_IO_MC
) {
1104 return ops
->vidioc_g_input(file
, fh
, arg
);
1107 static int v4l_g_output(const struct v4l2_ioctl_ops
*ops
,
1108 struct file
*file
, void *fh
, void *arg
)
1110 struct video_device
*vfd
= video_devdata(file
);
1112 if (vfd
->device_caps
& V4L2_CAP_IO_MC
) {
1117 return ops
->vidioc_g_output(file
, fh
, arg
);
1120 static int v4l_s_input(const struct v4l2_ioctl_ops
*ops
,
1121 struct file
*file
, void *fh
, void *arg
)
1123 struct video_device
*vfd
= video_devdata(file
);
1126 ret
= v4l_enable_media_source(vfd
);
1130 if (vfd
->device_caps
& V4L2_CAP_IO_MC
)
1131 return *(int *)arg
? -EINVAL
: 0;
1133 return ops
->vidioc_s_input(file
, fh
, *(unsigned int *)arg
);
1136 static int v4l_s_output(const struct v4l2_ioctl_ops
*ops
,
1137 struct file
*file
, void *fh
, void *arg
)
1139 struct video_device
*vfd
= video_devdata(file
);
1141 if (vfd
->device_caps
& V4L2_CAP_IO_MC
)
1142 return *(int *)arg
? -EINVAL
: 0;
1144 return ops
->vidioc_s_output(file
, fh
, *(unsigned int *)arg
);
1147 static int v4l_g_priority(const struct v4l2_ioctl_ops
*ops
,
1148 struct file
*file
, void *fh
, void *arg
)
1150 struct video_device
*vfd
;
1153 vfd
= video_devdata(file
);
1154 *p
= v4l2_prio_max(vfd
->prio
);
1158 static int v4l_s_priority(const struct v4l2_ioctl_ops
*ops
,
1159 struct file
*file
, void *fh
, void *arg
)
1161 struct video_device
*vfd
;
1162 struct v4l2_fh
*vfh
;
1165 vfd
= video_devdata(file
);
1166 if (!test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
))
1168 vfh
= file
->private_data
;
1169 return v4l2_prio_change(vfd
->prio
, &vfh
->prio
, *p
);
1172 static int v4l_enuminput(const struct v4l2_ioctl_ops
*ops
,
1173 struct file
*file
, void *fh
, void *arg
)
1175 struct video_device
*vfd
= video_devdata(file
);
1176 struct v4l2_input
*p
= arg
;
1179 * We set the flags for CAP_DV_TIMINGS &
1180 * CAP_STD here based on ioctl handler provided by the
1181 * driver. If the driver doesn't support these
1182 * for a specific input, it must override these flags.
1184 if (is_valid_ioctl(vfd
, VIDIOC_S_STD
))
1185 p
->capabilities
|= V4L2_IN_CAP_STD
;
1187 if (vfd
->device_caps
& V4L2_CAP_IO_MC
) {
1190 strscpy(p
->name
, vfd
->name
, sizeof(p
->name
));
1191 p
->type
= V4L2_INPUT_TYPE_CAMERA
;
1195 return ops
->vidioc_enum_input(file
, fh
, p
);
1198 static int v4l_enumoutput(const struct v4l2_ioctl_ops
*ops
,
1199 struct file
*file
, void *fh
, void *arg
)
1201 struct video_device
*vfd
= video_devdata(file
);
1202 struct v4l2_output
*p
= arg
;
1205 * We set the flags for CAP_DV_TIMINGS &
1206 * CAP_STD here based on ioctl handler provided by the
1207 * driver. If the driver doesn't support these
1208 * for a specific output, it must override these flags.
1210 if (is_valid_ioctl(vfd
, VIDIOC_S_STD
))
1211 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1213 if (vfd
->device_caps
& V4L2_CAP_IO_MC
) {
1216 strscpy(p
->name
, vfd
->name
, sizeof(p
->name
));
1217 p
->type
= V4L2_OUTPUT_TYPE_ANALOG
;
1221 return ops
->vidioc_enum_output(file
, fh
, p
);
1224 static void v4l_fill_fmtdesc(struct v4l2_fmtdesc
*fmt
)
1226 const unsigned sz
= sizeof(fmt
->description
);
1227 const char *descr
= NULL
;
1231 * We depart from the normal coding style here since the descriptions
1232 * should be aligned so it is easy to see which descriptions will be
1233 * longer than 31 characters (the max length for a description).
1234 * And frankly, this is easier to read anyway.
1236 * Note that gcc will use O(log N) comparisons to find the right case.
1238 switch (fmt
->pixelformat
) {
1239 /* Max description length mask: descr = "0123456789012345678901234567890" */
1240 case V4L2_PIX_FMT_RGB332
: descr
= "8-bit RGB 3-3-2"; break;
1241 case V4L2_PIX_FMT_RGB444
: descr
= "16-bit A/XRGB 4-4-4-4"; break;
1242 case V4L2_PIX_FMT_ARGB444
: descr
= "16-bit ARGB 4-4-4-4"; break;
1243 case V4L2_PIX_FMT_XRGB444
: descr
= "16-bit XRGB 4-4-4-4"; break;
1244 case V4L2_PIX_FMT_RGBA444
: descr
= "16-bit RGBA 4-4-4-4"; break;
1245 case V4L2_PIX_FMT_RGBX444
: descr
= "16-bit RGBX 4-4-4-4"; break;
1246 case V4L2_PIX_FMT_ABGR444
: descr
= "16-bit ABGR 4-4-4-4"; break;
1247 case V4L2_PIX_FMT_XBGR444
: descr
= "16-bit XBGR 4-4-4-4"; break;
1248 case V4L2_PIX_FMT_BGRA444
: descr
= "16-bit BGRA 4-4-4-4"; break;
1249 case V4L2_PIX_FMT_BGRX444
: descr
= "16-bit BGRX 4-4-4-4"; break;
1250 case V4L2_PIX_FMT_RGB555
: descr
= "16-bit A/XRGB 1-5-5-5"; break;
1251 case V4L2_PIX_FMT_ARGB555
: descr
= "16-bit ARGB 1-5-5-5"; break;
1252 case V4L2_PIX_FMT_XRGB555
: descr
= "16-bit XRGB 1-5-5-5"; break;
1253 case V4L2_PIX_FMT_ABGR555
: descr
= "16-bit ABGR 1-5-5-5"; break;
1254 case V4L2_PIX_FMT_XBGR555
: descr
= "16-bit XBGR 1-5-5-5"; break;
1255 case V4L2_PIX_FMT_RGBA555
: descr
= "16-bit RGBA 5-5-5-1"; break;
1256 case V4L2_PIX_FMT_RGBX555
: descr
= "16-bit RGBX 5-5-5-1"; break;
1257 case V4L2_PIX_FMT_BGRA555
: descr
= "16-bit BGRA 5-5-5-1"; break;
1258 case V4L2_PIX_FMT_BGRX555
: descr
= "16-bit BGRX 5-5-5-1"; break;
1259 case V4L2_PIX_FMT_RGB565
: descr
= "16-bit RGB 5-6-5"; break;
1260 case V4L2_PIX_FMT_RGB555X
: descr
= "16-bit A/XRGB 1-5-5-5 BE"; break;
1261 case V4L2_PIX_FMT_ARGB555X
: descr
= "16-bit ARGB 1-5-5-5 BE"; break;
1262 case V4L2_PIX_FMT_XRGB555X
: descr
= "16-bit XRGB 1-5-5-5 BE"; break;
1263 case V4L2_PIX_FMT_RGB565X
: descr
= "16-bit RGB 5-6-5 BE"; break;
1264 case V4L2_PIX_FMT_BGR666
: descr
= "18-bit BGRX 6-6-6-14"; break;
1265 case V4L2_PIX_FMT_BGR24
: descr
= "24-bit BGR 8-8-8"; break;
1266 case V4L2_PIX_FMT_RGB24
: descr
= "24-bit RGB 8-8-8"; break;
1267 case V4L2_PIX_FMT_BGR32
: descr
= "32-bit BGRA/X 8-8-8-8"; break;
1268 case V4L2_PIX_FMT_ABGR32
: descr
= "32-bit BGRA 8-8-8-8"; break;
1269 case V4L2_PIX_FMT_XBGR32
: descr
= "32-bit BGRX 8-8-8-8"; break;
1270 case V4L2_PIX_FMT_RGB32
: descr
= "32-bit A/XRGB 8-8-8-8"; break;
1271 case V4L2_PIX_FMT_ARGB32
: descr
= "32-bit ARGB 8-8-8-8"; break;
1272 case V4L2_PIX_FMT_XRGB32
: descr
= "32-bit XRGB 8-8-8-8"; break;
1273 case V4L2_PIX_FMT_BGRA32
: descr
= "32-bit ABGR 8-8-8-8"; break;
1274 case V4L2_PIX_FMT_BGRX32
: descr
= "32-bit XBGR 8-8-8-8"; break;
1275 case V4L2_PIX_FMT_RGBA32
: descr
= "32-bit RGBA 8-8-8-8"; break;
1276 case V4L2_PIX_FMT_RGBX32
: descr
= "32-bit RGBX 8-8-8-8"; break;
1277 case V4L2_PIX_FMT_GREY
: descr
= "8-bit Greyscale"; break;
1278 case V4L2_PIX_FMT_Y4
: descr
= "4-bit Greyscale"; break;
1279 case V4L2_PIX_FMT_Y6
: descr
= "6-bit Greyscale"; break;
1280 case V4L2_PIX_FMT_Y10
: descr
= "10-bit Greyscale"; break;
1281 case V4L2_PIX_FMT_Y12
: descr
= "12-bit Greyscale"; break;
1282 case V4L2_PIX_FMT_Y14
: descr
= "14-bit Greyscale"; break;
1283 case V4L2_PIX_FMT_Y16
: descr
= "16-bit Greyscale"; break;
1284 case V4L2_PIX_FMT_Y16_BE
: descr
= "16-bit Greyscale BE"; break;
1285 case V4L2_PIX_FMT_Y10BPACK
: descr
= "10-bit Greyscale (Packed)"; break;
1286 case V4L2_PIX_FMT_Y10P
: descr
= "10-bit Greyscale (MIPI Packed)"; break;
1287 case V4L2_PIX_FMT_Y8I
: descr
= "Interleaved 8-bit Greyscale"; break;
1288 case V4L2_PIX_FMT_Y12I
: descr
= "Interleaved 12-bit Greyscale"; break;
1289 case V4L2_PIX_FMT_Z16
: descr
= "16-bit Depth"; break;
1290 case V4L2_PIX_FMT_INZI
: descr
= "Planar 10:16 Greyscale Depth"; break;
1291 case V4L2_PIX_FMT_CNF4
: descr
= "4-bit Depth Confidence (Packed)"; break;
1292 case V4L2_PIX_FMT_PAL8
: descr
= "8-bit Palette"; break;
1293 case V4L2_PIX_FMT_UV8
: descr
= "8-bit Chrominance UV 4-4"; break;
1294 case V4L2_PIX_FMT_YVU410
: descr
= "Planar YVU 4:1:0"; break;
1295 case V4L2_PIX_FMT_YVU420
: descr
= "Planar YVU 4:2:0"; break;
1296 case V4L2_PIX_FMT_YUYV
: descr
= "YUYV 4:2:2"; break;
1297 case V4L2_PIX_FMT_YYUV
: descr
= "YYUV 4:2:2"; break;
1298 case V4L2_PIX_FMT_YVYU
: descr
= "YVYU 4:2:2"; break;
1299 case V4L2_PIX_FMT_UYVY
: descr
= "UYVY 4:2:2"; break;
1300 case V4L2_PIX_FMT_VYUY
: descr
= "VYUY 4:2:2"; break;
1301 case V4L2_PIX_FMT_YUV422P
: descr
= "Planar YUV 4:2:2"; break;
1302 case V4L2_PIX_FMT_YUV411P
: descr
= "Planar YUV 4:1:1"; break;
1303 case V4L2_PIX_FMT_Y41P
: descr
= "YUV 4:1:1 (Packed)"; break;
1304 case V4L2_PIX_FMT_YUV444
: descr
= "16-bit A/XYUV 4-4-4-4"; break;
1305 case V4L2_PIX_FMT_YUV555
: descr
= "16-bit A/XYUV 1-5-5-5"; break;
1306 case V4L2_PIX_FMT_YUV565
: descr
= "16-bit YUV 5-6-5"; break;
1307 case V4L2_PIX_FMT_YUV32
: descr
= "32-bit A/XYUV 8-8-8-8"; break;
1308 case V4L2_PIX_FMT_AYUV32
: descr
= "32-bit AYUV 8-8-8-8"; break;
1309 case V4L2_PIX_FMT_XYUV32
: descr
= "32-bit XYUV 8-8-8-8"; break;
1310 case V4L2_PIX_FMT_VUYA32
: descr
= "32-bit VUYA 8-8-8-8"; break;
1311 case V4L2_PIX_FMT_VUYX32
: descr
= "32-bit VUYX 8-8-8-8"; break;
1312 case V4L2_PIX_FMT_YUV410
: descr
= "Planar YUV 4:1:0"; break;
1313 case V4L2_PIX_FMT_YUV420
: descr
= "Planar YUV 4:2:0"; break;
1314 case V4L2_PIX_FMT_HI240
: descr
= "8-bit Dithered RGB (BTTV)"; break;
1315 case V4L2_PIX_FMT_HM12
: descr
= "YUV 4:2:0 (16x16 Macroblocks)"; break;
1316 case V4L2_PIX_FMT_M420
: descr
= "YUV 4:2:0 (M420)"; break;
1317 case V4L2_PIX_FMT_NV12
: descr
= "Y/CbCr 4:2:0"; break;
1318 case V4L2_PIX_FMT_NV21
: descr
= "Y/CrCb 4:2:0"; break;
1319 case V4L2_PIX_FMT_NV16
: descr
= "Y/CbCr 4:2:2"; break;
1320 case V4L2_PIX_FMT_NV61
: descr
= "Y/CrCb 4:2:2"; break;
1321 case V4L2_PIX_FMT_NV24
: descr
= "Y/CbCr 4:4:4"; break;
1322 case V4L2_PIX_FMT_NV42
: descr
= "Y/CrCb 4:4:4"; break;
1323 case V4L2_PIX_FMT_NV12M
: descr
= "Y/CbCr 4:2:0 (N-C)"; break;
1324 case V4L2_PIX_FMT_NV21M
: descr
= "Y/CrCb 4:2:0 (N-C)"; break;
1325 case V4L2_PIX_FMT_NV16M
: descr
= "Y/CbCr 4:2:2 (N-C)"; break;
1326 case V4L2_PIX_FMT_NV61M
: descr
= "Y/CrCb 4:2:2 (N-C)"; break;
1327 case V4L2_PIX_FMT_NV12MT
: descr
= "Y/CbCr 4:2:0 (64x32 MB, N-C)"; break;
1328 case V4L2_PIX_FMT_NV12MT_16X16
: descr
= "Y/CbCr 4:2:0 (16x16 MB, N-C)"; break;
1329 case V4L2_PIX_FMT_YUV420M
: descr
= "Planar YUV 4:2:0 (N-C)"; break;
1330 case V4L2_PIX_FMT_YVU420M
: descr
= "Planar YVU 4:2:0 (N-C)"; break;
1331 case V4L2_PIX_FMT_YUV422M
: descr
= "Planar YUV 4:2:2 (N-C)"; break;
1332 case V4L2_PIX_FMT_YVU422M
: descr
= "Planar YVU 4:2:2 (N-C)"; break;
1333 case V4L2_PIX_FMT_YUV444M
: descr
= "Planar YUV 4:4:4 (N-C)"; break;
1334 case V4L2_PIX_FMT_YVU444M
: descr
= "Planar YVU 4:4:4 (N-C)"; break;
1335 case V4L2_PIX_FMT_SBGGR8
: descr
= "8-bit Bayer BGBG/GRGR"; break;
1336 case V4L2_PIX_FMT_SGBRG8
: descr
= "8-bit Bayer GBGB/RGRG"; break;
1337 case V4L2_PIX_FMT_SGRBG8
: descr
= "8-bit Bayer GRGR/BGBG"; break;
1338 case V4L2_PIX_FMT_SRGGB8
: descr
= "8-bit Bayer RGRG/GBGB"; break;
1339 case V4L2_PIX_FMT_SBGGR10
: descr
= "10-bit Bayer BGBG/GRGR"; break;
1340 case V4L2_PIX_FMT_SGBRG10
: descr
= "10-bit Bayer GBGB/RGRG"; break;
1341 case V4L2_PIX_FMT_SGRBG10
: descr
= "10-bit Bayer GRGR/BGBG"; break;
1342 case V4L2_PIX_FMT_SRGGB10
: descr
= "10-bit Bayer RGRG/GBGB"; break;
1343 case V4L2_PIX_FMT_SBGGR10P
: descr
= "10-bit Bayer BGBG/GRGR Packed"; break;
1344 case V4L2_PIX_FMT_SGBRG10P
: descr
= "10-bit Bayer GBGB/RGRG Packed"; break;
1345 case V4L2_PIX_FMT_SGRBG10P
: descr
= "10-bit Bayer GRGR/BGBG Packed"; break;
1346 case V4L2_PIX_FMT_SRGGB10P
: descr
= "10-bit Bayer RGRG/GBGB Packed"; break;
1347 case V4L2_PIX_FMT_IPU3_SBGGR10
: descr
= "10-bit bayer BGGR IPU3 Packed"; break;
1348 case V4L2_PIX_FMT_IPU3_SGBRG10
: descr
= "10-bit bayer GBRG IPU3 Packed"; break;
1349 case V4L2_PIX_FMT_IPU3_SGRBG10
: descr
= "10-bit bayer GRBG IPU3 Packed"; break;
1350 case V4L2_PIX_FMT_IPU3_SRGGB10
: descr
= "10-bit bayer RGGB IPU3 Packed"; break;
1351 case V4L2_PIX_FMT_SBGGR10ALAW8
: descr
= "8-bit Bayer BGBG/GRGR (A-law)"; break;
1352 case V4L2_PIX_FMT_SGBRG10ALAW8
: descr
= "8-bit Bayer GBGB/RGRG (A-law)"; break;
1353 case V4L2_PIX_FMT_SGRBG10ALAW8
: descr
= "8-bit Bayer GRGR/BGBG (A-law)"; break;
1354 case V4L2_PIX_FMT_SRGGB10ALAW8
: descr
= "8-bit Bayer RGRG/GBGB (A-law)"; break;
1355 case V4L2_PIX_FMT_SBGGR10DPCM8
: descr
= "8-bit Bayer BGBG/GRGR (DPCM)"; break;
1356 case V4L2_PIX_FMT_SGBRG10DPCM8
: descr
= "8-bit Bayer GBGB/RGRG (DPCM)"; break;
1357 case V4L2_PIX_FMT_SGRBG10DPCM8
: descr
= "8-bit Bayer GRGR/BGBG (DPCM)"; break;
1358 case V4L2_PIX_FMT_SRGGB10DPCM8
: descr
= "8-bit Bayer RGRG/GBGB (DPCM)"; break;
1359 case V4L2_PIX_FMT_SBGGR12
: descr
= "12-bit Bayer BGBG/GRGR"; break;
1360 case V4L2_PIX_FMT_SGBRG12
: descr
= "12-bit Bayer GBGB/RGRG"; break;
1361 case V4L2_PIX_FMT_SGRBG12
: descr
= "12-bit Bayer GRGR/BGBG"; break;
1362 case V4L2_PIX_FMT_SRGGB12
: descr
= "12-bit Bayer RGRG/GBGB"; break;
1363 case V4L2_PIX_FMT_SBGGR12P
: descr
= "12-bit Bayer BGBG/GRGR Packed"; break;
1364 case V4L2_PIX_FMT_SGBRG12P
: descr
= "12-bit Bayer GBGB/RGRG Packed"; break;
1365 case V4L2_PIX_FMT_SGRBG12P
: descr
= "12-bit Bayer GRGR/BGBG Packed"; break;
1366 case V4L2_PIX_FMT_SRGGB12P
: descr
= "12-bit Bayer RGRG/GBGB Packed"; break;
1367 case V4L2_PIX_FMT_SBGGR14
: descr
= "14-bit Bayer BGBG/GRGR"; break;
1368 case V4L2_PIX_FMT_SGBRG14
: descr
= "14-bit Bayer GBGB/RGRG"; break;
1369 case V4L2_PIX_FMT_SGRBG14
: descr
= "14-bit Bayer GRGR/BGBG"; break;
1370 case V4L2_PIX_FMT_SRGGB14
: descr
= "14-bit Bayer RGRG/GBGB"; break;
1371 case V4L2_PIX_FMT_SBGGR14P
: descr
= "14-bit Bayer BGBG/GRGR Packed"; break;
1372 case V4L2_PIX_FMT_SGBRG14P
: descr
= "14-bit Bayer GBGB/RGRG Packed"; break;
1373 case V4L2_PIX_FMT_SGRBG14P
: descr
= "14-bit Bayer GRGR/BGBG Packed"; break;
1374 case V4L2_PIX_FMT_SRGGB14P
: descr
= "14-bit Bayer RGRG/GBGB Packed"; break;
1375 case V4L2_PIX_FMT_SBGGR16
: descr
= "16-bit Bayer BGBG/GRGR"; break;
1376 case V4L2_PIX_FMT_SGBRG16
: descr
= "16-bit Bayer GBGB/RGRG"; break;
1377 case V4L2_PIX_FMT_SGRBG16
: descr
= "16-bit Bayer GRGR/BGBG"; break;
1378 case V4L2_PIX_FMT_SRGGB16
: descr
= "16-bit Bayer RGRG/GBGB"; break;
1379 case V4L2_PIX_FMT_SN9C20X_I420
: descr
= "GSPCA SN9C20X I420"; break;
1380 case V4L2_PIX_FMT_SPCA501
: descr
= "GSPCA SPCA501"; break;
1381 case V4L2_PIX_FMT_SPCA505
: descr
= "GSPCA SPCA505"; break;
1382 case V4L2_PIX_FMT_SPCA508
: descr
= "GSPCA SPCA508"; break;
1383 case V4L2_PIX_FMT_STV0680
: descr
= "GSPCA STV0680"; break;
1384 case V4L2_PIX_FMT_TM6000
: descr
= "A/V + VBI Mux Packet"; break;
1385 case V4L2_PIX_FMT_CIT_YYVYUY
: descr
= "GSPCA CIT YYVYUY"; break;
1386 case V4L2_PIX_FMT_KONICA420
: descr
= "GSPCA KONICA420"; break;
1387 case V4L2_PIX_FMT_HSV24
: descr
= "24-bit HSV 8-8-8"; break;
1388 case V4L2_PIX_FMT_HSV32
: descr
= "32-bit XHSV 8-8-8-8"; break;
1389 case V4L2_SDR_FMT_CU8
: descr
= "Complex U8"; break;
1390 case V4L2_SDR_FMT_CU16LE
: descr
= "Complex U16LE"; break;
1391 case V4L2_SDR_FMT_CS8
: descr
= "Complex S8"; break;
1392 case V4L2_SDR_FMT_CS14LE
: descr
= "Complex S14LE"; break;
1393 case V4L2_SDR_FMT_RU12LE
: descr
= "Real U12LE"; break;
1394 case V4L2_SDR_FMT_PCU16BE
: descr
= "Planar Complex U16BE"; break;
1395 case V4L2_SDR_FMT_PCU18BE
: descr
= "Planar Complex U18BE"; break;
1396 case V4L2_SDR_FMT_PCU20BE
: descr
= "Planar Complex U20BE"; break;
1397 case V4L2_TCH_FMT_DELTA_TD16
: descr
= "16-bit Signed Deltas"; break;
1398 case V4L2_TCH_FMT_DELTA_TD08
: descr
= "8-bit Signed Deltas"; break;
1399 case V4L2_TCH_FMT_TU16
: descr
= "16-bit Unsigned Touch Data"; break;
1400 case V4L2_TCH_FMT_TU08
: descr
= "8-bit Unsigned Touch Data"; break;
1401 case V4L2_META_FMT_VSP1_HGO
: descr
= "R-Car VSP1 1-D Histogram"; break;
1402 case V4L2_META_FMT_VSP1_HGT
: descr
= "R-Car VSP1 2-D Histogram"; break;
1403 case V4L2_META_FMT_UVC
: descr
= "UVC Payload Header Metadata"; break;
1404 case V4L2_META_FMT_D4XX
: descr
= "Intel D4xx UVC Metadata"; break;
1405 case V4L2_META_FMT_VIVID
: descr
= "Vivid Metadata"; break;
1406 case V4L2_META_FMT_RK_ISP1_PARAMS
: descr
= "Rockchip ISP1 3A Parameters"; break;
1407 case V4L2_META_FMT_RK_ISP1_STAT_3A
: descr
= "Rockchip ISP1 3A Statistics"; break;
1410 /* Compressed formats */
1411 flags
= V4L2_FMT_FLAG_COMPRESSED
;
1412 switch (fmt
->pixelformat
) {
1413 /* Max description length mask: descr = "0123456789012345678901234567890" */
1414 case V4L2_PIX_FMT_MJPEG
: descr
= "Motion-JPEG"; break;
1415 case V4L2_PIX_FMT_JPEG
: descr
= "JFIF JPEG"; break;
1416 case V4L2_PIX_FMT_DV
: descr
= "1394"; break;
1417 case V4L2_PIX_FMT_MPEG
: descr
= "MPEG-1/2/4"; break;
1418 case V4L2_PIX_FMT_H264
: descr
= "H.264"; break;
1419 case V4L2_PIX_FMT_H264_NO_SC
: descr
= "H.264 (No Start Codes)"; break;
1420 case V4L2_PIX_FMT_H264_MVC
: descr
= "H.264 MVC"; break;
1421 case V4L2_PIX_FMT_H264_SLICE
: descr
= "H.264 Parsed Slice Data"; break;
1422 case V4L2_PIX_FMT_H263
: descr
= "H.263"; break;
1423 case V4L2_PIX_FMT_MPEG1
: descr
= "MPEG-1 ES"; break;
1424 case V4L2_PIX_FMT_MPEG2
: descr
= "MPEG-2 ES"; break;
1425 case V4L2_PIX_FMT_MPEG2_SLICE
: descr
= "MPEG-2 Parsed Slice Data"; break;
1426 case V4L2_PIX_FMT_MPEG4
: descr
= "MPEG-4 Part 2 ES"; break;
1427 case V4L2_PIX_FMT_XVID
: descr
= "Xvid"; break;
1428 case V4L2_PIX_FMT_VC1_ANNEX_G
: descr
= "VC-1 (SMPTE 412M Annex G)"; break;
1429 case V4L2_PIX_FMT_VC1_ANNEX_L
: descr
= "VC-1 (SMPTE 412M Annex L)"; break;
1430 case V4L2_PIX_FMT_VP8
: descr
= "VP8"; break;
1431 case V4L2_PIX_FMT_VP8_FRAME
: descr
= "VP8 Frame"; break;
1432 case V4L2_PIX_FMT_VP9
: descr
= "VP9"; break;
1433 case V4L2_PIX_FMT_HEVC
: descr
= "HEVC"; break; /* aka H.265 */
1434 case V4L2_PIX_FMT_HEVC_SLICE
: descr
= "HEVC Parsed Slice Data"; break;
1435 case V4L2_PIX_FMT_FWHT
: descr
= "FWHT"; break; /* used in vicodec */
1436 case V4L2_PIX_FMT_FWHT_STATELESS
: descr
= "FWHT Stateless"; break; /* used in vicodec */
1437 case V4L2_PIX_FMT_CPIA1
: descr
= "GSPCA CPiA YUV"; break;
1438 case V4L2_PIX_FMT_WNVA
: descr
= "WNVA"; break;
1439 case V4L2_PIX_FMT_SN9C10X
: descr
= "GSPCA SN9C10X"; break;
1440 case V4L2_PIX_FMT_PWC1
: descr
= "Raw Philips Webcam Type (Old)"; break;
1441 case V4L2_PIX_FMT_PWC2
: descr
= "Raw Philips Webcam Type (New)"; break;
1442 case V4L2_PIX_FMT_ET61X251
: descr
= "GSPCA ET61X251"; break;
1443 case V4L2_PIX_FMT_SPCA561
: descr
= "GSPCA SPCA561"; break;
1444 case V4L2_PIX_FMT_PAC207
: descr
= "GSPCA PAC207"; break;
1445 case V4L2_PIX_FMT_MR97310A
: descr
= "GSPCA MR97310A"; break;
1446 case V4L2_PIX_FMT_JL2005BCD
: descr
= "GSPCA JL2005BCD"; break;
1447 case V4L2_PIX_FMT_SN9C2028
: descr
= "GSPCA SN9C2028"; break;
1448 case V4L2_PIX_FMT_SQ905C
: descr
= "GSPCA SQ905C"; break;
1449 case V4L2_PIX_FMT_PJPG
: descr
= "GSPCA PJPG"; break;
1450 case V4L2_PIX_FMT_OV511
: descr
= "GSPCA OV511"; break;
1451 case V4L2_PIX_FMT_OV518
: descr
= "GSPCA OV518"; break;
1452 case V4L2_PIX_FMT_JPGL
: descr
= "JPEG Lite"; break;
1453 case V4L2_PIX_FMT_SE401
: descr
= "GSPCA SE401"; break;
1454 case V4L2_PIX_FMT_S5C_UYVY_JPG
: descr
= "S5C73MX interleaved UYVY/JPEG"; break;
1455 case V4L2_PIX_FMT_MT21C
: descr
= "Mediatek Compressed Format"; break;
1456 case V4L2_PIX_FMT_SUNXI_TILED_NV12
: descr
= "Sunxi Tiled NV12 Format"; break;
1458 if (fmt
->description
[0])
1460 WARN(1, "Unknown pixelformat 0x%08x\n", fmt
->pixelformat
);
1462 snprintf(fmt
->description
, sz
, "%c%c%c%c%s",
1463 (char)(fmt
->pixelformat
& 0x7f),
1464 (char)((fmt
->pixelformat
>> 8) & 0x7f),
1465 (char)((fmt
->pixelformat
>> 16) & 0x7f),
1466 (char)((fmt
->pixelformat
>> 24) & 0x7f),
1467 (fmt
->pixelformat
& (1UL << 31)) ? "-BE" : "");
1473 WARN_ON(strscpy(fmt
->description
, descr
, sz
) < 0);
1474 fmt
->flags
|= flags
;
1477 static int v4l_enum_fmt(const struct v4l2_ioctl_ops
*ops
,
1478 struct file
*file
, void *fh
, void *arg
)
1480 struct video_device
*vdev
= video_devdata(file
);
1481 struct v4l2_fmtdesc
*p
= arg
;
1482 int ret
= check_fmt(file
, p
->type
);
1490 if (!(vdev
->device_caps
& V4L2_CAP_IO_MC
))
1493 mbus_code
= p
->mbus_code
;
1494 CLEAR_AFTER_FIELD(p
, type
);
1495 p
->mbus_code
= mbus_code
;
1498 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1499 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1500 cap_mask
= V4L2_CAP_VIDEO_CAPTURE_MPLANE
|
1501 V4L2_CAP_VIDEO_M2M_MPLANE
;
1502 if (!!(vdev
->device_caps
& cap_mask
) !=
1503 (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
))
1506 if (unlikely(!ops
->vidioc_enum_fmt_vid_cap
))
1508 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, arg
);
1510 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1511 if (unlikely(!ops
->vidioc_enum_fmt_vid_overlay
))
1513 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
, fh
, arg
);
1515 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1516 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1517 cap_mask
= V4L2_CAP_VIDEO_OUTPUT_MPLANE
|
1518 V4L2_CAP_VIDEO_M2M_MPLANE
;
1519 if (!!(vdev
->device_caps
& cap_mask
) !=
1520 (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
))
1523 if (unlikely(!ops
->vidioc_enum_fmt_vid_out
))
1525 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, arg
);
1527 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1528 if (unlikely(!ops
->vidioc_enum_fmt_sdr_cap
))
1530 ret
= ops
->vidioc_enum_fmt_sdr_cap(file
, fh
, arg
);
1532 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1533 if (unlikely(!ops
->vidioc_enum_fmt_sdr_out
))
1535 ret
= ops
->vidioc_enum_fmt_sdr_out(file
, fh
, arg
);
1537 case V4L2_BUF_TYPE_META_CAPTURE
:
1538 if (unlikely(!ops
->vidioc_enum_fmt_meta_cap
))
1540 ret
= ops
->vidioc_enum_fmt_meta_cap(file
, fh
, arg
);
1542 case V4L2_BUF_TYPE_META_OUTPUT
:
1543 if (unlikely(!ops
->vidioc_enum_fmt_meta_out
))
1545 ret
= ops
->vidioc_enum_fmt_meta_out(file
, fh
, arg
);
1549 v4l_fill_fmtdesc(p
);
1553 static void v4l_pix_format_touch(struct v4l2_pix_format
*p
)
1556 * The v4l2_pix_format structure contains fields that make no sense for
1557 * touch. Set them to default values in this case.
1560 p
->field
= V4L2_FIELD_NONE
;
1561 p
->colorspace
= V4L2_COLORSPACE_RAW
;
1564 p
->quantization
= 0;
1568 static int v4l_g_fmt(const struct v4l2_ioctl_ops
*ops
,
1569 struct file
*file
, void *fh
, void *arg
)
1571 struct v4l2_format
*p
= arg
;
1572 struct video_device
*vfd
= video_devdata(file
);
1573 int ret
= check_fmt(file
, p
->type
);
1579 * fmt can't be cleared for these overlay types due to the 'clips'
1580 * 'clipcount' and 'bitmap' pointers in struct v4l2_window.
1581 * Those are provided by the user. So handle these two overlay types
1582 * first, and then just do a simple memset for the other types.
1585 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1586 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
: {
1587 struct v4l2_clip
*clips
= p
->fmt
.win
.clips
;
1588 u32 clipcount
= p
->fmt
.win
.clipcount
;
1589 void __user
*bitmap
= p
->fmt
.win
.bitmap
;
1591 memset(&p
->fmt
, 0, sizeof(p
->fmt
));
1592 p
->fmt
.win
.clips
= clips
;
1593 p
->fmt
.win
.clipcount
= clipcount
;
1594 p
->fmt
.win
.bitmap
= bitmap
;
1598 memset(&p
->fmt
, 0, sizeof(p
->fmt
));
1603 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1604 if (unlikely(!ops
->vidioc_g_fmt_vid_cap
))
1606 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1607 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, arg
);
1608 /* just in case the driver zeroed it again */
1609 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1610 if (vfd
->vfl_type
== VFL_TYPE_TOUCH
)
1611 v4l_pix_format_touch(&p
->fmt
.pix
);
1613 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1614 return ops
->vidioc_g_fmt_vid_cap_mplane(file
, fh
, arg
);
1615 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1616 return ops
->vidioc_g_fmt_vid_overlay(file
, fh
, arg
);
1617 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1618 return ops
->vidioc_g_fmt_vbi_cap(file
, fh
, arg
);
1619 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
1620 return ops
->vidioc_g_fmt_sliced_vbi_cap(file
, fh
, arg
);
1621 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1622 if (unlikely(!ops
->vidioc_g_fmt_vid_out
))
1624 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1625 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, arg
);
1626 /* just in case the driver zeroed it again */
1627 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1629 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1630 return ops
->vidioc_g_fmt_vid_out_mplane(file
, fh
, arg
);
1631 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
1632 return ops
->vidioc_g_fmt_vid_out_overlay(file
, fh
, arg
);
1633 case V4L2_BUF_TYPE_VBI_OUTPUT
:
1634 return ops
->vidioc_g_fmt_vbi_out(file
, fh
, arg
);
1635 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1636 return ops
->vidioc_g_fmt_sliced_vbi_out(file
, fh
, arg
);
1637 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1638 return ops
->vidioc_g_fmt_sdr_cap(file
, fh
, arg
);
1639 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1640 return ops
->vidioc_g_fmt_sdr_out(file
, fh
, arg
);
1641 case V4L2_BUF_TYPE_META_CAPTURE
:
1642 return ops
->vidioc_g_fmt_meta_cap(file
, fh
, arg
);
1643 case V4L2_BUF_TYPE_META_OUTPUT
:
1644 return ops
->vidioc_g_fmt_meta_out(file
, fh
, arg
);
1649 static int v4l_s_fmt(const struct v4l2_ioctl_ops
*ops
,
1650 struct file
*file
, void *fh
, void *arg
)
1652 struct v4l2_format
*p
= arg
;
1653 struct video_device
*vfd
= video_devdata(file
);
1654 int ret
= check_fmt(file
, p
->type
);
1660 ret
= v4l_enable_media_source(vfd
);
1663 v4l_sanitize_format(p
);
1666 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1667 if (unlikely(!ops
->vidioc_s_fmt_vid_cap
))
1669 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1670 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, arg
);
1671 /* just in case the driver zeroed it again */
1672 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1673 if (vfd
->vfl_type
== VFL_TYPE_TOUCH
)
1674 v4l_pix_format_touch(&p
->fmt
.pix
);
1676 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1677 if (unlikely(!ops
->vidioc_s_fmt_vid_cap_mplane
))
1679 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1680 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1681 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1683 return ops
->vidioc_s_fmt_vid_cap_mplane(file
, fh
, arg
);
1684 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1685 if (unlikely(!ops
->vidioc_s_fmt_vid_overlay
))
1687 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1688 return ops
->vidioc_s_fmt_vid_overlay(file
, fh
, arg
);
1689 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1690 if (unlikely(!ops
->vidioc_s_fmt_vbi_cap
))
1692 CLEAR_AFTER_FIELD(p
, fmt
.vbi
.flags
);
1693 return ops
->vidioc_s_fmt_vbi_cap(file
, fh
, arg
);
1694 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
1695 if (unlikely(!ops
->vidioc_s_fmt_sliced_vbi_cap
))
1697 CLEAR_AFTER_FIELD(p
, fmt
.sliced
.io_size
);
1698 return ops
->vidioc_s_fmt_sliced_vbi_cap(file
, fh
, arg
);
1699 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1700 if (unlikely(!ops
->vidioc_s_fmt_vid_out
))
1702 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1703 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, arg
);
1704 /* just in case the driver zeroed it again */
1705 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1707 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1708 if (unlikely(!ops
->vidioc_s_fmt_vid_out_mplane
))
1710 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1711 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1712 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1714 return ops
->vidioc_s_fmt_vid_out_mplane(file
, fh
, arg
);
1715 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
1716 if (unlikely(!ops
->vidioc_s_fmt_vid_out_overlay
))
1718 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1719 return ops
->vidioc_s_fmt_vid_out_overlay(file
, fh
, arg
);
1720 case V4L2_BUF_TYPE_VBI_OUTPUT
:
1721 if (unlikely(!ops
->vidioc_s_fmt_vbi_out
))
1723 CLEAR_AFTER_FIELD(p
, fmt
.vbi
.flags
);
1724 return ops
->vidioc_s_fmt_vbi_out(file
, fh
, arg
);
1725 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1726 if (unlikely(!ops
->vidioc_s_fmt_sliced_vbi_out
))
1728 CLEAR_AFTER_FIELD(p
, fmt
.sliced
.io_size
);
1729 return ops
->vidioc_s_fmt_sliced_vbi_out(file
, fh
, arg
);
1730 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1731 if (unlikely(!ops
->vidioc_s_fmt_sdr_cap
))
1733 CLEAR_AFTER_FIELD(p
, fmt
.sdr
.buffersize
);
1734 return ops
->vidioc_s_fmt_sdr_cap(file
, fh
, arg
);
1735 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1736 if (unlikely(!ops
->vidioc_s_fmt_sdr_out
))
1738 CLEAR_AFTER_FIELD(p
, fmt
.sdr
.buffersize
);
1739 return ops
->vidioc_s_fmt_sdr_out(file
, fh
, arg
);
1740 case V4L2_BUF_TYPE_META_CAPTURE
:
1741 if (unlikely(!ops
->vidioc_s_fmt_meta_cap
))
1743 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1744 return ops
->vidioc_s_fmt_meta_cap(file
, fh
, arg
);
1745 case V4L2_BUF_TYPE_META_OUTPUT
:
1746 if (unlikely(!ops
->vidioc_s_fmt_meta_out
))
1748 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1749 return ops
->vidioc_s_fmt_meta_out(file
, fh
, arg
);
1754 static int v4l_try_fmt(const struct v4l2_ioctl_ops
*ops
,
1755 struct file
*file
, void *fh
, void *arg
)
1757 struct v4l2_format
*p
= arg
;
1758 struct video_device
*vfd
= video_devdata(file
);
1759 int ret
= check_fmt(file
, p
->type
);
1765 v4l_sanitize_format(p
);
1768 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1769 if (unlikely(!ops
->vidioc_try_fmt_vid_cap
))
1771 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1772 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, arg
);
1773 /* just in case the driver zeroed it again */
1774 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1775 if (vfd
->vfl_type
== VFL_TYPE_TOUCH
)
1776 v4l_pix_format_touch(&p
->fmt
.pix
);
1778 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1779 if (unlikely(!ops
->vidioc_try_fmt_vid_cap_mplane
))
1781 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1782 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1783 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1785 return ops
->vidioc_try_fmt_vid_cap_mplane(file
, fh
, arg
);
1786 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1787 if (unlikely(!ops
->vidioc_try_fmt_vid_overlay
))
1789 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1790 return ops
->vidioc_try_fmt_vid_overlay(file
, fh
, arg
);
1791 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1792 if (unlikely(!ops
->vidioc_try_fmt_vbi_cap
))
1794 CLEAR_AFTER_FIELD(p
, fmt
.vbi
.flags
);
1795 return ops
->vidioc_try_fmt_vbi_cap(file
, fh
, arg
);
1796 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
1797 if (unlikely(!ops
->vidioc_try_fmt_sliced_vbi_cap
))
1799 CLEAR_AFTER_FIELD(p
, fmt
.sliced
.io_size
);
1800 return ops
->vidioc_try_fmt_sliced_vbi_cap(file
, fh
, arg
);
1801 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1802 if (unlikely(!ops
->vidioc_try_fmt_vid_out
))
1804 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1805 ret
= ops
->vidioc_try_fmt_vid_out(file
, fh
, arg
);
1806 /* just in case the driver zeroed it again */
1807 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1809 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1810 if (unlikely(!ops
->vidioc_try_fmt_vid_out_mplane
))
1812 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1813 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1814 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1816 return ops
->vidioc_try_fmt_vid_out_mplane(file
, fh
, arg
);
1817 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
1818 if (unlikely(!ops
->vidioc_try_fmt_vid_out_overlay
))
1820 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1821 return ops
->vidioc_try_fmt_vid_out_overlay(file
, fh
, arg
);
1822 case V4L2_BUF_TYPE_VBI_OUTPUT
:
1823 if (unlikely(!ops
->vidioc_try_fmt_vbi_out
))
1825 CLEAR_AFTER_FIELD(p
, fmt
.vbi
.flags
);
1826 return ops
->vidioc_try_fmt_vbi_out(file
, fh
, arg
);
1827 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1828 if (unlikely(!ops
->vidioc_try_fmt_sliced_vbi_out
))
1830 CLEAR_AFTER_FIELD(p
, fmt
.sliced
.io_size
);
1831 return ops
->vidioc_try_fmt_sliced_vbi_out(file
, fh
, arg
);
1832 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1833 if (unlikely(!ops
->vidioc_try_fmt_sdr_cap
))
1835 CLEAR_AFTER_FIELD(p
, fmt
.sdr
.buffersize
);
1836 return ops
->vidioc_try_fmt_sdr_cap(file
, fh
, arg
);
1837 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1838 if (unlikely(!ops
->vidioc_try_fmt_sdr_out
))
1840 CLEAR_AFTER_FIELD(p
, fmt
.sdr
.buffersize
);
1841 return ops
->vidioc_try_fmt_sdr_out(file
, fh
, arg
);
1842 case V4L2_BUF_TYPE_META_CAPTURE
:
1843 if (unlikely(!ops
->vidioc_try_fmt_meta_cap
))
1845 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1846 return ops
->vidioc_try_fmt_meta_cap(file
, fh
, arg
);
1847 case V4L2_BUF_TYPE_META_OUTPUT
:
1848 if (unlikely(!ops
->vidioc_try_fmt_meta_out
))
1850 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1851 return ops
->vidioc_try_fmt_meta_out(file
, fh
, arg
);
1856 static int v4l_streamon(const struct v4l2_ioctl_ops
*ops
,
1857 struct file
*file
, void *fh
, void *arg
)
1859 return ops
->vidioc_streamon(file
, fh
, *(unsigned int *)arg
);
1862 static int v4l_streamoff(const struct v4l2_ioctl_ops
*ops
,
1863 struct file
*file
, void *fh
, void *arg
)
1865 return ops
->vidioc_streamoff(file
, fh
, *(unsigned int *)arg
);
1868 static int v4l_g_tuner(const struct v4l2_ioctl_ops
*ops
,
1869 struct file
*file
, void *fh
, void *arg
)
1871 struct video_device
*vfd
= video_devdata(file
);
1872 struct v4l2_tuner
*p
= arg
;
1875 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1876 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1877 err
= ops
->vidioc_g_tuner(file
, fh
, p
);
1879 p
->capability
|= V4L2_TUNER_CAP_FREQ_BANDS
;
1883 static int v4l_s_tuner(const struct v4l2_ioctl_ops
*ops
,
1884 struct file
*file
, void *fh
, void *arg
)
1886 struct video_device
*vfd
= video_devdata(file
);
1887 struct v4l2_tuner
*p
= arg
;
1890 ret
= v4l_enable_media_source(vfd
);
1893 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1894 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1895 return ops
->vidioc_s_tuner(file
, fh
, p
);
1898 static int v4l_g_modulator(const struct v4l2_ioctl_ops
*ops
,
1899 struct file
*file
, void *fh
, void *arg
)
1901 struct video_device
*vfd
= video_devdata(file
);
1902 struct v4l2_modulator
*p
= arg
;
1905 if (vfd
->vfl_type
== VFL_TYPE_RADIO
)
1906 p
->type
= V4L2_TUNER_RADIO
;
1908 err
= ops
->vidioc_g_modulator(file
, fh
, p
);
1910 p
->capability
|= V4L2_TUNER_CAP_FREQ_BANDS
;
1914 static int v4l_s_modulator(const struct v4l2_ioctl_ops
*ops
,
1915 struct file
*file
, void *fh
, void *arg
)
1917 struct video_device
*vfd
= video_devdata(file
);
1918 struct v4l2_modulator
*p
= arg
;
1920 if (vfd
->vfl_type
== VFL_TYPE_RADIO
)
1921 p
->type
= V4L2_TUNER_RADIO
;
1923 return ops
->vidioc_s_modulator(file
, fh
, p
);
1926 static int v4l_g_frequency(const struct v4l2_ioctl_ops
*ops
,
1927 struct file
*file
, void *fh
, void *arg
)
1929 struct video_device
*vfd
= video_devdata(file
);
1930 struct v4l2_frequency
*p
= arg
;
1932 if (vfd
->vfl_type
== VFL_TYPE_SDR
)
1933 p
->type
= V4L2_TUNER_SDR
;
1935 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1936 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1937 return ops
->vidioc_g_frequency(file
, fh
, p
);
1940 static int v4l_s_frequency(const struct v4l2_ioctl_ops
*ops
,
1941 struct file
*file
, void *fh
, void *arg
)
1943 struct video_device
*vfd
= video_devdata(file
);
1944 const struct v4l2_frequency
*p
= arg
;
1945 enum v4l2_tuner_type type
;
1948 ret
= v4l_enable_media_source(vfd
);
1951 if (vfd
->vfl_type
== VFL_TYPE_SDR
) {
1952 if (p
->type
!= V4L2_TUNER_SDR
&& p
->type
!= V4L2_TUNER_RF
)
1955 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1956 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1957 if (type
!= p
->type
)
1960 return ops
->vidioc_s_frequency(file
, fh
, p
);
1963 static int v4l_enumstd(const struct v4l2_ioctl_ops
*ops
,
1964 struct file
*file
, void *fh
, void *arg
)
1966 struct video_device
*vfd
= video_devdata(file
);
1967 struct v4l2_standard
*p
= arg
;
1969 return v4l_video_std_enumstd(p
, vfd
->tvnorms
);
1972 static int v4l_s_std(const struct v4l2_ioctl_ops
*ops
,
1973 struct file
*file
, void *fh
, void *arg
)
1975 struct video_device
*vfd
= video_devdata(file
);
1976 v4l2_std_id id
= *(v4l2_std_id
*)arg
, norm
;
1979 ret
= v4l_enable_media_source(vfd
);
1982 norm
= id
& vfd
->tvnorms
;
1983 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1986 /* Calls the specific handler */
1987 return ops
->vidioc_s_std(file
, fh
, norm
);
1990 static int v4l_querystd(const struct v4l2_ioctl_ops
*ops
,
1991 struct file
*file
, void *fh
, void *arg
)
1993 struct video_device
*vfd
= video_devdata(file
);
1994 v4l2_std_id
*p
= arg
;
1997 ret
= v4l_enable_media_source(vfd
);
2001 * If no signal is detected, then the driver should return
2002 * V4L2_STD_UNKNOWN. Otherwise it should return tvnorms with
2003 * any standards that do not apply removed.
2005 * This means that tuners, audio and video decoders can join
2006 * their efforts to improve the standards detection.
2009 return ops
->vidioc_querystd(file
, fh
, arg
);
2012 static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops
*ops
,
2013 struct file
*file
, void *fh
, void *arg
)
2015 struct video_device
*vfd
= video_devdata(file
);
2016 struct v4l2_hw_freq_seek
*p
= arg
;
2017 enum v4l2_tuner_type type
;
2020 ret
= v4l_enable_media_source(vfd
);
2023 /* s_hw_freq_seek is not supported for SDR for now */
2024 if (vfd
->vfl_type
== VFL_TYPE_SDR
)
2027 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
2028 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
2029 if (p
->type
!= type
)
2031 return ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
2034 static int v4l_overlay(const struct v4l2_ioctl_ops
*ops
,
2035 struct file
*file
, void *fh
, void *arg
)
2037 return ops
->vidioc_overlay(file
, fh
, *(unsigned int *)arg
);
2040 static int v4l_reqbufs(const struct v4l2_ioctl_ops
*ops
,
2041 struct file
*file
, void *fh
, void *arg
)
2043 struct v4l2_requestbuffers
*p
= arg
;
2044 int ret
= check_fmt(file
, p
->type
);
2049 CLEAR_AFTER_FIELD(p
, capabilities
);
2051 return ops
->vidioc_reqbufs(file
, fh
, p
);
2054 static int v4l_querybuf(const struct v4l2_ioctl_ops
*ops
,
2055 struct file
*file
, void *fh
, void *arg
)
2057 struct v4l2_buffer
*p
= arg
;
2058 int ret
= check_fmt(file
, p
->type
);
2060 return ret
? ret
: ops
->vidioc_querybuf(file
, fh
, p
);
2063 static int v4l_qbuf(const struct v4l2_ioctl_ops
*ops
,
2064 struct file
*file
, void *fh
, void *arg
)
2066 struct v4l2_buffer
*p
= arg
;
2067 int ret
= check_fmt(file
, p
->type
);
2069 return ret
? ret
: ops
->vidioc_qbuf(file
, fh
, p
);
2072 static int v4l_dqbuf(const struct v4l2_ioctl_ops
*ops
,
2073 struct file
*file
, void *fh
, void *arg
)
2075 struct v4l2_buffer
*p
= arg
;
2076 int ret
= check_fmt(file
, p
->type
);
2078 return ret
? ret
: ops
->vidioc_dqbuf(file
, fh
, p
);
2081 static int v4l_create_bufs(const struct v4l2_ioctl_ops
*ops
,
2082 struct file
*file
, void *fh
, void *arg
)
2084 struct v4l2_create_buffers
*create
= arg
;
2085 int ret
= check_fmt(file
, create
->format
.type
);
2090 CLEAR_AFTER_FIELD(create
, capabilities
);
2092 v4l_sanitize_format(&create
->format
);
2094 ret
= ops
->vidioc_create_bufs(file
, fh
, create
);
2096 if (create
->format
.type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
||
2097 create
->format
.type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
2098 create
->format
.fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
2103 static int v4l_prepare_buf(const struct v4l2_ioctl_ops
*ops
,
2104 struct file
*file
, void *fh
, void *arg
)
2106 struct v4l2_buffer
*b
= arg
;
2107 int ret
= check_fmt(file
, b
->type
);
2109 return ret
? ret
: ops
->vidioc_prepare_buf(file
, fh
, b
);
2112 static int v4l_g_parm(const struct v4l2_ioctl_ops
*ops
,
2113 struct file
*file
, void *fh
, void *arg
)
2115 struct v4l2_streamparm
*p
= arg
;
2117 int ret
= check_fmt(file
, p
->type
);
2121 if (ops
->vidioc_g_parm
)
2122 return ops
->vidioc_g_parm(file
, fh
, p
);
2123 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
2124 p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2126 p
->parm
.capture
.readbuffers
= 2;
2127 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
2129 v4l2_video_std_frame_period(std
, &p
->parm
.capture
.timeperframe
);
2133 static int v4l_s_parm(const struct v4l2_ioctl_ops
*ops
,
2134 struct file
*file
, void *fh
, void *arg
)
2136 struct v4l2_streamparm
*p
= arg
;
2137 int ret
= check_fmt(file
, p
->type
);
2142 /* Note: extendedmode is never used in drivers */
2143 if (V4L2_TYPE_IS_OUTPUT(p
->type
)) {
2144 memset(p
->parm
.output
.reserved
, 0,
2145 sizeof(p
->parm
.output
.reserved
));
2146 p
->parm
.output
.extendedmode
= 0;
2147 p
->parm
.output
.outputmode
&= V4L2_MODE_HIGHQUALITY
;
2149 memset(p
->parm
.capture
.reserved
, 0,
2150 sizeof(p
->parm
.capture
.reserved
));
2151 p
->parm
.capture
.extendedmode
= 0;
2152 p
->parm
.capture
.capturemode
&= V4L2_MODE_HIGHQUALITY
;
2154 return ops
->vidioc_s_parm(file
, fh
, p
);
2157 static int v4l_queryctrl(const struct v4l2_ioctl_ops
*ops
,
2158 struct file
*file
, void *fh
, void *arg
)
2160 struct video_device
*vfd
= video_devdata(file
);
2161 struct v4l2_queryctrl
*p
= arg
;
2162 struct v4l2_fh
*vfh
=
2163 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2165 if (vfh
&& vfh
->ctrl_handler
)
2166 return v4l2_queryctrl(vfh
->ctrl_handler
, p
);
2167 if (vfd
->ctrl_handler
)
2168 return v4l2_queryctrl(vfd
->ctrl_handler
, p
);
2169 if (ops
->vidioc_queryctrl
)
2170 return ops
->vidioc_queryctrl(file
, fh
, p
);
2174 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops
*ops
,
2175 struct file
*file
, void *fh
, void *arg
)
2177 struct video_device
*vfd
= video_devdata(file
);
2178 struct v4l2_query_ext_ctrl
*p
= arg
;
2179 struct v4l2_fh
*vfh
=
2180 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2182 if (vfh
&& vfh
->ctrl_handler
)
2183 return v4l2_query_ext_ctrl(vfh
->ctrl_handler
, p
);
2184 if (vfd
->ctrl_handler
)
2185 return v4l2_query_ext_ctrl(vfd
->ctrl_handler
, p
);
2186 if (ops
->vidioc_query_ext_ctrl
)
2187 return ops
->vidioc_query_ext_ctrl(file
, fh
, p
);
2191 static int v4l_querymenu(const struct v4l2_ioctl_ops
*ops
,
2192 struct file
*file
, void *fh
, void *arg
)
2194 struct video_device
*vfd
= video_devdata(file
);
2195 struct v4l2_querymenu
*p
= arg
;
2196 struct v4l2_fh
*vfh
=
2197 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2199 if (vfh
&& vfh
->ctrl_handler
)
2200 return v4l2_querymenu(vfh
->ctrl_handler
, p
);
2201 if (vfd
->ctrl_handler
)
2202 return v4l2_querymenu(vfd
->ctrl_handler
, p
);
2203 if (ops
->vidioc_querymenu
)
2204 return ops
->vidioc_querymenu(file
, fh
, p
);
2208 static int v4l_g_ctrl(const struct v4l2_ioctl_ops
*ops
,
2209 struct file
*file
, void *fh
, void *arg
)
2211 struct video_device
*vfd
= video_devdata(file
);
2212 struct v4l2_control
*p
= arg
;
2213 struct v4l2_fh
*vfh
=
2214 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2215 struct v4l2_ext_controls ctrls
;
2216 struct v4l2_ext_control ctrl
;
2218 if (vfh
&& vfh
->ctrl_handler
)
2219 return v4l2_g_ctrl(vfh
->ctrl_handler
, p
);
2220 if (vfd
->ctrl_handler
)
2221 return v4l2_g_ctrl(vfd
->ctrl_handler
, p
);
2222 if (ops
->vidioc_g_ctrl
)
2223 return ops
->vidioc_g_ctrl(file
, fh
, p
);
2224 if (ops
->vidioc_g_ext_ctrls
== NULL
)
2227 ctrls
.which
= V4L2_CTRL_ID2WHICH(p
->id
);
2229 ctrls
.controls
= &ctrl
;
2231 ctrl
.value
= p
->value
;
2232 if (check_ext_ctrls(&ctrls
, 1)) {
2233 int ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
2236 p
->value
= ctrl
.value
;
2242 static int v4l_s_ctrl(const struct v4l2_ioctl_ops
*ops
,
2243 struct file
*file
, void *fh
, void *arg
)
2245 struct video_device
*vfd
= video_devdata(file
);
2246 struct v4l2_control
*p
= arg
;
2247 struct v4l2_fh
*vfh
=
2248 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2249 struct v4l2_ext_controls ctrls
;
2250 struct v4l2_ext_control ctrl
;
2252 if (vfh
&& vfh
->ctrl_handler
)
2253 return v4l2_s_ctrl(vfh
, vfh
->ctrl_handler
, p
);
2254 if (vfd
->ctrl_handler
)
2255 return v4l2_s_ctrl(NULL
, vfd
->ctrl_handler
, p
);
2256 if (ops
->vidioc_s_ctrl
)
2257 return ops
->vidioc_s_ctrl(file
, fh
, p
);
2258 if (ops
->vidioc_s_ext_ctrls
== NULL
)
2261 ctrls
.which
= V4L2_CTRL_ID2WHICH(p
->id
);
2263 ctrls
.controls
= &ctrl
;
2265 ctrl
.value
= p
->value
;
2266 if (check_ext_ctrls(&ctrls
, 1))
2267 return ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
2271 static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops
*ops
,
2272 struct file
*file
, void *fh
, void *arg
)
2274 struct video_device
*vfd
= video_devdata(file
);
2275 struct v4l2_ext_controls
*p
= arg
;
2276 struct v4l2_fh
*vfh
=
2277 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2279 p
->error_idx
= p
->count
;
2280 if (vfh
&& vfh
->ctrl_handler
)
2281 return v4l2_g_ext_ctrls(vfh
->ctrl_handler
,
2282 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2283 if (vfd
->ctrl_handler
)
2284 return v4l2_g_ext_ctrls(vfd
->ctrl_handler
,
2285 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2286 if (ops
->vidioc_g_ext_ctrls
== NULL
)
2288 return check_ext_ctrls(p
, 0) ? ops
->vidioc_g_ext_ctrls(file
, fh
, p
) :
2292 static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops
*ops
,
2293 struct file
*file
, void *fh
, void *arg
)
2295 struct video_device
*vfd
= video_devdata(file
);
2296 struct v4l2_ext_controls
*p
= arg
;
2297 struct v4l2_fh
*vfh
=
2298 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2300 p
->error_idx
= p
->count
;
2301 if (vfh
&& vfh
->ctrl_handler
)
2302 return v4l2_s_ext_ctrls(vfh
, vfh
->ctrl_handler
,
2303 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2304 if (vfd
->ctrl_handler
)
2305 return v4l2_s_ext_ctrls(NULL
, vfd
->ctrl_handler
,
2306 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2307 if (ops
->vidioc_s_ext_ctrls
== NULL
)
2309 return check_ext_ctrls(p
, 0) ? ops
->vidioc_s_ext_ctrls(file
, fh
, p
) :
2313 static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops
*ops
,
2314 struct file
*file
, void *fh
, void *arg
)
2316 struct video_device
*vfd
= video_devdata(file
);
2317 struct v4l2_ext_controls
*p
= arg
;
2318 struct v4l2_fh
*vfh
=
2319 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2321 p
->error_idx
= p
->count
;
2322 if (vfh
&& vfh
->ctrl_handler
)
2323 return v4l2_try_ext_ctrls(vfh
->ctrl_handler
,
2324 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2325 if (vfd
->ctrl_handler
)
2326 return v4l2_try_ext_ctrls(vfd
->ctrl_handler
,
2327 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2328 if (ops
->vidioc_try_ext_ctrls
== NULL
)
2330 return check_ext_ctrls(p
, 0) ? ops
->vidioc_try_ext_ctrls(file
, fh
, p
) :
2335 * The selection API specified originally that the _MPLANE buffer types
2336 * shouldn't be used. The reasons for this are lost in the mists of time
2337 * (or just really crappy memories). Regardless, this is really annoying
2338 * for userspace. So to keep things simple we map _MPLANE buffer types
2339 * to their 'regular' counterparts before calling the driver. And we
2340 * restore it afterwards. This way applications can use either buffer
2341 * type and drivers don't need to check for both.
2343 static int v4l_g_selection(const struct v4l2_ioctl_ops
*ops
,
2344 struct file
*file
, void *fh
, void *arg
)
2346 struct v4l2_selection
*p
= arg
;
2347 u32 old_type
= p
->type
;
2350 if (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2351 p
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2352 else if (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
2353 p
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
2354 ret
= ops
->vidioc_g_selection(file
, fh
, p
);
2359 static int v4l_s_selection(const struct v4l2_ioctl_ops
*ops
,
2360 struct file
*file
, void *fh
, void *arg
)
2362 struct v4l2_selection
*p
= arg
;
2363 u32 old_type
= p
->type
;
2366 if (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2367 p
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2368 else if (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
2369 p
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
2370 ret
= ops
->vidioc_s_selection(file
, fh
, p
);
2375 static int v4l_g_crop(const struct v4l2_ioctl_ops
*ops
,
2376 struct file
*file
, void *fh
, void *arg
)
2378 struct video_device
*vfd
= video_devdata(file
);
2379 struct v4l2_crop
*p
= arg
;
2380 struct v4l2_selection s
= {
2385 /* simulate capture crop using selection api */
2387 /* crop means compose for output devices */
2388 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
2389 s
.target
= V4L2_SEL_TGT_COMPOSE
;
2391 s
.target
= V4L2_SEL_TGT_CROP
;
2393 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP
, &vfd
->flags
))
2394 s
.target
= s
.target
== V4L2_SEL_TGT_COMPOSE
?
2395 V4L2_SEL_TGT_CROP
: V4L2_SEL_TGT_COMPOSE
;
2397 ret
= v4l_g_selection(ops
, file
, fh
, &s
);
2399 /* copying results to old structure on success */
2405 static int v4l_s_crop(const struct v4l2_ioctl_ops
*ops
,
2406 struct file
*file
, void *fh
, void *arg
)
2408 struct video_device
*vfd
= video_devdata(file
);
2409 struct v4l2_crop
*p
= arg
;
2410 struct v4l2_selection s
= {
2415 /* simulate capture crop using selection api */
2417 /* crop means compose for output devices */
2418 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
2419 s
.target
= V4L2_SEL_TGT_COMPOSE
;
2421 s
.target
= V4L2_SEL_TGT_CROP
;
2423 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP
, &vfd
->flags
))
2424 s
.target
= s
.target
== V4L2_SEL_TGT_COMPOSE
?
2425 V4L2_SEL_TGT_CROP
: V4L2_SEL_TGT_COMPOSE
;
2427 return v4l_s_selection(ops
, file
, fh
, &s
);
2430 static int v4l_cropcap(const struct v4l2_ioctl_ops
*ops
,
2431 struct file
*file
, void *fh
, void *arg
)
2433 struct video_device
*vfd
= video_devdata(file
);
2434 struct v4l2_cropcap
*p
= arg
;
2435 struct v4l2_selection s
= { .type
= p
->type
};
2438 /* setting trivial pixelaspect */
2439 p
->pixelaspect
.numerator
= 1;
2440 p
->pixelaspect
.denominator
= 1;
2442 if (s
.type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2443 s
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2444 else if (s
.type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
2445 s
.type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
2448 * The determine_valid_ioctls() call already should ensure
2449 * that this can never happen, but just in case...
2451 if (WARN_ON(!ops
->vidioc_g_selection
))
2454 if (ops
->vidioc_g_pixelaspect
)
2455 ret
= ops
->vidioc_g_pixelaspect(file
, fh
, s
.type
,
2459 * Ignore ENOTTY or ENOIOCTLCMD error returns, just use the
2460 * square pixel aspect ratio in that case.
2462 if (ret
&& ret
!= -ENOTTY
&& ret
!= -ENOIOCTLCMD
)
2465 /* Use g_selection() to fill in the bounds and defrect rectangles */
2467 /* obtaining bounds */
2468 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
2469 s
.target
= V4L2_SEL_TGT_COMPOSE_BOUNDS
;
2471 s
.target
= V4L2_SEL_TGT_CROP_BOUNDS
;
2473 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP
, &vfd
->flags
))
2474 s
.target
= s
.target
== V4L2_SEL_TGT_COMPOSE_BOUNDS
?
2475 V4L2_SEL_TGT_CROP_BOUNDS
: V4L2_SEL_TGT_COMPOSE_BOUNDS
;
2477 ret
= v4l_g_selection(ops
, file
, fh
, &s
);
2482 /* obtaining defrect */
2483 if (s
.target
== V4L2_SEL_TGT_COMPOSE_BOUNDS
)
2484 s
.target
= V4L2_SEL_TGT_COMPOSE_DEFAULT
;
2486 s
.target
= V4L2_SEL_TGT_CROP_DEFAULT
;
2488 ret
= v4l_g_selection(ops
, file
, fh
, &s
);
2496 static int v4l_log_status(const struct v4l2_ioctl_ops
*ops
,
2497 struct file
*file
, void *fh
, void *arg
)
2499 struct video_device
*vfd
= video_devdata(file
);
2503 pr_info("%s: ================= START STATUS =================\n",
2504 vfd
->v4l2_dev
->name
);
2505 ret
= ops
->vidioc_log_status(file
, fh
);
2507 pr_info("%s: ================== END STATUS ==================\n",
2508 vfd
->v4l2_dev
->name
);
2512 static int v4l_dbg_g_register(const struct v4l2_ioctl_ops
*ops
,
2513 struct file
*file
, void *fh
, void *arg
)
2515 #ifdef CONFIG_VIDEO_ADV_DEBUG
2516 struct v4l2_dbg_register
*p
= arg
;
2517 struct video_device
*vfd
= video_devdata(file
);
2518 struct v4l2_subdev
*sd
;
2521 if (!capable(CAP_SYS_ADMIN
))
2523 if (p
->match
.type
== V4L2_CHIP_MATCH_SUBDEV
) {
2524 if (vfd
->v4l2_dev
== NULL
)
2526 v4l2_device_for_each_subdev(sd
, vfd
->v4l2_dev
)
2527 if (p
->match
.addr
== idx
++)
2528 return v4l2_subdev_call(sd
, core
, g_register
, p
);
2531 if (ops
->vidioc_g_register
&& p
->match
.type
== V4L2_CHIP_MATCH_BRIDGE
&&
2532 (ops
->vidioc_g_chip_info
|| p
->match
.addr
== 0))
2533 return ops
->vidioc_g_register(file
, fh
, p
);
2540 static int v4l_dbg_s_register(const struct v4l2_ioctl_ops
*ops
,
2541 struct file
*file
, void *fh
, void *arg
)
2543 #ifdef CONFIG_VIDEO_ADV_DEBUG
2544 const struct v4l2_dbg_register
*p
= arg
;
2545 struct video_device
*vfd
= video_devdata(file
);
2546 struct v4l2_subdev
*sd
;
2549 if (!capable(CAP_SYS_ADMIN
))
2551 if (p
->match
.type
== V4L2_CHIP_MATCH_SUBDEV
) {
2552 if (vfd
->v4l2_dev
== NULL
)
2554 v4l2_device_for_each_subdev(sd
, vfd
->v4l2_dev
)
2555 if (p
->match
.addr
== idx
++)
2556 return v4l2_subdev_call(sd
, core
, s_register
, p
);
2559 if (ops
->vidioc_s_register
&& p
->match
.type
== V4L2_CHIP_MATCH_BRIDGE
&&
2560 (ops
->vidioc_g_chip_info
|| p
->match
.addr
== 0))
2561 return ops
->vidioc_s_register(file
, fh
, p
);
2568 static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops
*ops
,
2569 struct file
*file
, void *fh
, void *arg
)
2571 #ifdef CONFIG_VIDEO_ADV_DEBUG
2572 struct video_device
*vfd
= video_devdata(file
);
2573 struct v4l2_dbg_chip_info
*p
= arg
;
2574 struct v4l2_subdev
*sd
;
2577 switch (p
->match
.type
) {
2578 case V4L2_CHIP_MATCH_BRIDGE
:
2579 if (ops
->vidioc_s_register
)
2580 p
->flags
|= V4L2_CHIP_FL_WRITABLE
;
2581 if (ops
->vidioc_g_register
)
2582 p
->flags
|= V4L2_CHIP_FL_READABLE
;
2583 strscpy(p
->name
, vfd
->v4l2_dev
->name
, sizeof(p
->name
));
2584 if (ops
->vidioc_g_chip_info
)
2585 return ops
->vidioc_g_chip_info(file
, fh
, arg
);
2590 case V4L2_CHIP_MATCH_SUBDEV
:
2591 if (vfd
->v4l2_dev
== NULL
)
2593 v4l2_device_for_each_subdev(sd
, vfd
->v4l2_dev
) {
2594 if (p
->match
.addr
!= idx
++)
2596 if (sd
->ops
->core
&& sd
->ops
->core
->s_register
)
2597 p
->flags
|= V4L2_CHIP_FL_WRITABLE
;
2598 if (sd
->ops
->core
&& sd
->ops
->core
->g_register
)
2599 p
->flags
|= V4L2_CHIP_FL_READABLE
;
2600 strscpy(p
->name
, sd
->name
, sizeof(p
->name
));
2611 static int v4l_dqevent(const struct v4l2_ioctl_ops
*ops
,
2612 struct file
*file
, void *fh
, void *arg
)
2614 return v4l2_event_dequeue(fh
, arg
, file
->f_flags
& O_NONBLOCK
);
2617 static int v4l_subscribe_event(const struct v4l2_ioctl_ops
*ops
,
2618 struct file
*file
, void *fh
, void *arg
)
2620 return ops
->vidioc_subscribe_event(fh
, arg
);
2623 static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops
*ops
,
2624 struct file
*file
, void *fh
, void *arg
)
2626 return ops
->vidioc_unsubscribe_event(fh
, arg
);
2629 static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops
*ops
,
2630 struct file
*file
, void *fh
, void *arg
)
2632 struct v4l2_sliced_vbi_cap
*p
= arg
;
2633 int ret
= check_fmt(file
, p
->type
);
2638 /* Clear up to type, everything after type is zeroed already */
2639 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
2641 return ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
2644 static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops
*ops
,
2645 struct file
*file
, void *fh
, void *arg
)
2647 struct video_device
*vfd
= video_devdata(file
);
2648 struct v4l2_frequency_band
*p
= arg
;
2649 enum v4l2_tuner_type type
;
2652 if (vfd
->vfl_type
== VFL_TYPE_SDR
) {
2653 if (p
->type
!= V4L2_TUNER_SDR
&& p
->type
!= V4L2_TUNER_RF
)
2657 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
2658 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
2659 if (type
!= p
->type
)
2662 if (ops
->vidioc_enum_freq_bands
) {
2663 err
= ops
->vidioc_enum_freq_bands(file
, fh
, p
);
2667 if (is_valid_ioctl(vfd
, VIDIOC_G_TUNER
)) {
2668 struct v4l2_tuner t
= {
2675 err
= ops
->vidioc_g_tuner(file
, fh
, &t
);
2678 p
->capability
= t
.capability
| V4L2_TUNER_CAP_FREQ_BANDS
;
2679 p
->rangelow
= t
.rangelow
;
2680 p
->rangehigh
= t
.rangehigh
;
2681 p
->modulation
= (type
== V4L2_TUNER_RADIO
) ?
2682 V4L2_BAND_MODULATION_FM
: V4L2_BAND_MODULATION_VSB
;
2685 if (is_valid_ioctl(vfd
, VIDIOC_G_MODULATOR
)) {
2686 struct v4l2_modulator m
= {
2690 if (type
!= V4L2_TUNER_RADIO
)
2694 err
= ops
->vidioc_g_modulator(file
, fh
, &m
);
2697 p
->capability
= m
.capability
| V4L2_TUNER_CAP_FREQ_BANDS
;
2698 p
->rangelow
= m
.rangelow
;
2699 p
->rangehigh
= m
.rangehigh
;
2700 p
->modulation
= (type
== V4L2_TUNER_RADIO
) ?
2701 V4L2_BAND_MODULATION_FM
: V4L2_BAND_MODULATION_VSB
;
2707 struct v4l2_ioctl_info
{
2710 const char * const name
;
2711 int (*func
)(const struct v4l2_ioctl_ops
*ops
, struct file
*file
,
2713 void (*debug
)(const void *arg
, bool write_only
);
2716 /* This control needs a priority check */
2717 #define INFO_FL_PRIO (1 << 0)
2718 /* This control can be valid if the filehandle passes a control handler. */
2719 #define INFO_FL_CTRL (1 << 1)
2721 #define INFO_FL_QUEUE (1 << 2)
2722 /* Always copy back result, even on error */
2723 #define INFO_FL_ALWAYS_COPY (1 << 3)
2724 /* Zero struct from after the field to the end */
2725 #define INFO_FL_CLEAR(v4l2_struct, field) \
2726 ((offsetof(struct v4l2_struct, field) + \
2727 sizeof_field(struct v4l2_struct, field)) << 16)
2728 #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
2730 #define DEFINE_V4L_STUB_FUNC(_vidioc) \
2731 static int v4l_stub_ ## _vidioc( \
2732 const struct v4l2_ioctl_ops *ops, \
2733 struct file *file, void *fh, void *p) \
2735 return ops->vidioc_ ## _vidioc(file, fh, p); \
2738 #define IOCTL_INFO(_ioctl, _func, _debug, _flags) \
2739 [_IOC_NR(_ioctl)] = { \
2747 DEFINE_V4L_STUB_FUNC(g_fbuf
)
2748 DEFINE_V4L_STUB_FUNC(s_fbuf
)
2749 DEFINE_V4L_STUB_FUNC(expbuf
)
2750 DEFINE_V4L_STUB_FUNC(g_std
)
2751 DEFINE_V4L_STUB_FUNC(g_audio
)
2752 DEFINE_V4L_STUB_FUNC(s_audio
)
2753 DEFINE_V4L_STUB_FUNC(g_edid
)
2754 DEFINE_V4L_STUB_FUNC(s_edid
)
2755 DEFINE_V4L_STUB_FUNC(g_audout
)
2756 DEFINE_V4L_STUB_FUNC(s_audout
)
2757 DEFINE_V4L_STUB_FUNC(g_jpegcomp
)
2758 DEFINE_V4L_STUB_FUNC(s_jpegcomp
)
2759 DEFINE_V4L_STUB_FUNC(enumaudio
)
2760 DEFINE_V4L_STUB_FUNC(enumaudout
)
2761 DEFINE_V4L_STUB_FUNC(enum_framesizes
)
2762 DEFINE_V4L_STUB_FUNC(enum_frameintervals
)
2763 DEFINE_V4L_STUB_FUNC(g_enc_index
)
2764 DEFINE_V4L_STUB_FUNC(encoder_cmd
)
2765 DEFINE_V4L_STUB_FUNC(try_encoder_cmd
)
2766 DEFINE_V4L_STUB_FUNC(decoder_cmd
)
2767 DEFINE_V4L_STUB_FUNC(try_decoder_cmd
)
2768 DEFINE_V4L_STUB_FUNC(s_dv_timings
)
2769 DEFINE_V4L_STUB_FUNC(g_dv_timings
)
2770 DEFINE_V4L_STUB_FUNC(enum_dv_timings
)
2771 DEFINE_V4L_STUB_FUNC(query_dv_timings
)
2772 DEFINE_V4L_STUB_FUNC(dv_timings_cap
)
2774 static const struct v4l2_ioctl_info v4l2_ioctls
[] = {
2775 IOCTL_INFO(VIDIOC_QUERYCAP
, v4l_querycap
, v4l_print_querycap
, 0),
2776 IOCTL_INFO(VIDIOC_ENUM_FMT
, v4l_enum_fmt
, v4l_print_fmtdesc
, 0),
2777 IOCTL_INFO(VIDIOC_G_FMT
, v4l_g_fmt
, v4l_print_format
, 0),
2778 IOCTL_INFO(VIDIOC_S_FMT
, v4l_s_fmt
, v4l_print_format
, INFO_FL_PRIO
),
2779 IOCTL_INFO(VIDIOC_REQBUFS
, v4l_reqbufs
, v4l_print_requestbuffers
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2780 IOCTL_INFO(VIDIOC_QUERYBUF
, v4l_querybuf
, v4l_print_buffer
, INFO_FL_QUEUE
| INFO_FL_CLEAR(v4l2_buffer
, length
)),
2781 IOCTL_INFO(VIDIOC_G_FBUF
, v4l_stub_g_fbuf
, v4l_print_framebuffer
, 0),
2782 IOCTL_INFO(VIDIOC_S_FBUF
, v4l_stub_s_fbuf
, v4l_print_framebuffer
, INFO_FL_PRIO
),
2783 IOCTL_INFO(VIDIOC_OVERLAY
, v4l_overlay
, v4l_print_u32
, INFO_FL_PRIO
),
2784 IOCTL_INFO(VIDIOC_QBUF
, v4l_qbuf
, v4l_print_buffer
, INFO_FL_QUEUE
),
2785 IOCTL_INFO(VIDIOC_EXPBUF
, v4l_stub_expbuf
, v4l_print_exportbuffer
, INFO_FL_QUEUE
| INFO_FL_CLEAR(v4l2_exportbuffer
, flags
)),
2786 IOCTL_INFO(VIDIOC_DQBUF
, v4l_dqbuf
, v4l_print_buffer
, INFO_FL_QUEUE
),
2787 IOCTL_INFO(VIDIOC_STREAMON
, v4l_streamon
, v4l_print_buftype
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2788 IOCTL_INFO(VIDIOC_STREAMOFF
, v4l_streamoff
, v4l_print_buftype
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2789 IOCTL_INFO(VIDIOC_G_PARM
, v4l_g_parm
, v4l_print_streamparm
, INFO_FL_CLEAR(v4l2_streamparm
, type
)),
2790 IOCTL_INFO(VIDIOC_S_PARM
, v4l_s_parm
, v4l_print_streamparm
, INFO_FL_PRIO
),
2791 IOCTL_INFO(VIDIOC_G_STD
, v4l_stub_g_std
, v4l_print_std
, 0),
2792 IOCTL_INFO(VIDIOC_S_STD
, v4l_s_std
, v4l_print_std
, INFO_FL_PRIO
),
2793 IOCTL_INFO(VIDIOC_ENUMSTD
, v4l_enumstd
, v4l_print_standard
, INFO_FL_CLEAR(v4l2_standard
, index
)),
2794 IOCTL_INFO(VIDIOC_ENUMINPUT
, v4l_enuminput
, v4l_print_enuminput
, INFO_FL_CLEAR(v4l2_input
, index
)),
2795 IOCTL_INFO(VIDIOC_G_CTRL
, v4l_g_ctrl
, v4l_print_control
, INFO_FL_CTRL
| INFO_FL_CLEAR(v4l2_control
, id
)),
2796 IOCTL_INFO(VIDIOC_S_CTRL
, v4l_s_ctrl
, v4l_print_control
, INFO_FL_PRIO
| INFO_FL_CTRL
),
2797 IOCTL_INFO(VIDIOC_G_TUNER
, v4l_g_tuner
, v4l_print_tuner
, INFO_FL_CLEAR(v4l2_tuner
, index
)),
2798 IOCTL_INFO(VIDIOC_S_TUNER
, v4l_s_tuner
, v4l_print_tuner
, INFO_FL_PRIO
),
2799 IOCTL_INFO(VIDIOC_G_AUDIO
, v4l_stub_g_audio
, v4l_print_audio
, 0),
2800 IOCTL_INFO(VIDIOC_S_AUDIO
, v4l_stub_s_audio
, v4l_print_audio
, INFO_FL_PRIO
),
2801 IOCTL_INFO(VIDIOC_QUERYCTRL
, v4l_queryctrl
, v4l_print_queryctrl
, INFO_FL_CTRL
| INFO_FL_CLEAR(v4l2_queryctrl
, id
)),
2802 IOCTL_INFO(VIDIOC_QUERYMENU
, v4l_querymenu
, v4l_print_querymenu
, INFO_FL_CTRL
| INFO_FL_CLEAR(v4l2_querymenu
, index
)),
2803 IOCTL_INFO(VIDIOC_G_INPUT
, v4l_g_input
, v4l_print_u32
, 0),
2804 IOCTL_INFO(VIDIOC_S_INPUT
, v4l_s_input
, v4l_print_u32
, INFO_FL_PRIO
),
2805 IOCTL_INFO(VIDIOC_G_EDID
, v4l_stub_g_edid
, v4l_print_edid
, INFO_FL_ALWAYS_COPY
),
2806 IOCTL_INFO(VIDIOC_S_EDID
, v4l_stub_s_edid
, v4l_print_edid
, INFO_FL_PRIO
| INFO_FL_ALWAYS_COPY
),
2807 IOCTL_INFO(VIDIOC_G_OUTPUT
, v4l_g_output
, v4l_print_u32
, 0),
2808 IOCTL_INFO(VIDIOC_S_OUTPUT
, v4l_s_output
, v4l_print_u32
, INFO_FL_PRIO
),
2809 IOCTL_INFO(VIDIOC_ENUMOUTPUT
, v4l_enumoutput
, v4l_print_enumoutput
, INFO_FL_CLEAR(v4l2_output
, index
)),
2810 IOCTL_INFO(VIDIOC_G_AUDOUT
, v4l_stub_g_audout
, v4l_print_audioout
, 0),
2811 IOCTL_INFO(VIDIOC_S_AUDOUT
, v4l_stub_s_audout
, v4l_print_audioout
, INFO_FL_PRIO
),
2812 IOCTL_INFO(VIDIOC_G_MODULATOR
, v4l_g_modulator
, v4l_print_modulator
, INFO_FL_CLEAR(v4l2_modulator
, index
)),
2813 IOCTL_INFO(VIDIOC_S_MODULATOR
, v4l_s_modulator
, v4l_print_modulator
, INFO_FL_PRIO
),
2814 IOCTL_INFO(VIDIOC_G_FREQUENCY
, v4l_g_frequency
, v4l_print_frequency
, INFO_FL_CLEAR(v4l2_frequency
, tuner
)),
2815 IOCTL_INFO(VIDIOC_S_FREQUENCY
, v4l_s_frequency
, v4l_print_frequency
, INFO_FL_PRIO
),
2816 IOCTL_INFO(VIDIOC_CROPCAP
, v4l_cropcap
, v4l_print_cropcap
, INFO_FL_CLEAR(v4l2_cropcap
, type
)),
2817 IOCTL_INFO(VIDIOC_G_CROP
, v4l_g_crop
, v4l_print_crop
, INFO_FL_CLEAR(v4l2_crop
, type
)),
2818 IOCTL_INFO(VIDIOC_S_CROP
, v4l_s_crop
, v4l_print_crop
, INFO_FL_PRIO
),
2819 IOCTL_INFO(VIDIOC_G_SELECTION
, v4l_g_selection
, v4l_print_selection
, INFO_FL_CLEAR(v4l2_selection
, r
)),
2820 IOCTL_INFO(VIDIOC_S_SELECTION
, v4l_s_selection
, v4l_print_selection
, INFO_FL_PRIO
| INFO_FL_CLEAR(v4l2_selection
, r
)),
2821 IOCTL_INFO(VIDIOC_G_JPEGCOMP
, v4l_stub_g_jpegcomp
, v4l_print_jpegcompression
, 0),
2822 IOCTL_INFO(VIDIOC_S_JPEGCOMP
, v4l_stub_s_jpegcomp
, v4l_print_jpegcompression
, INFO_FL_PRIO
),
2823 IOCTL_INFO(VIDIOC_QUERYSTD
, v4l_querystd
, v4l_print_std
, 0),
2824 IOCTL_INFO(VIDIOC_TRY_FMT
, v4l_try_fmt
, v4l_print_format
, 0),
2825 IOCTL_INFO(VIDIOC_ENUMAUDIO
, v4l_stub_enumaudio
, v4l_print_audio
, INFO_FL_CLEAR(v4l2_audio
, index
)),
2826 IOCTL_INFO(VIDIOC_ENUMAUDOUT
, v4l_stub_enumaudout
, v4l_print_audioout
, INFO_FL_CLEAR(v4l2_audioout
, index
)),
2827 IOCTL_INFO(VIDIOC_G_PRIORITY
, v4l_g_priority
, v4l_print_u32
, 0),
2828 IOCTL_INFO(VIDIOC_S_PRIORITY
, v4l_s_priority
, v4l_print_u32
, INFO_FL_PRIO
),
2829 IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP
, v4l_g_sliced_vbi_cap
, v4l_print_sliced_vbi_cap
, INFO_FL_CLEAR(v4l2_sliced_vbi_cap
, type
)),
2830 IOCTL_INFO(VIDIOC_LOG_STATUS
, v4l_log_status
, v4l_print_newline
, 0),
2831 IOCTL_INFO(VIDIOC_G_EXT_CTRLS
, v4l_g_ext_ctrls
, v4l_print_ext_controls
, INFO_FL_CTRL
),
2832 IOCTL_INFO(VIDIOC_S_EXT_CTRLS
, v4l_s_ext_ctrls
, v4l_print_ext_controls
, INFO_FL_PRIO
| INFO_FL_CTRL
),
2833 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS
, v4l_try_ext_ctrls
, v4l_print_ext_controls
, INFO_FL_CTRL
),
2834 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES
, v4l_stub_enum_framesizes
, v4l_print_frmsizeenum
, INFO_FL_CLEAR(v4l2_frmsizeenum
, pixel_format
)),
2835 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS
, v4l_stub_enum_frameintervals
, v4l_print_frmivalenum
, INFO_FL_CLEAR(v4l2_frmivalenum
, height
)),
2836 IOCTL_INFO(VIDIOC_G_ENC_INDEX
, v4l_stub_g_enc_index
, v4l_print_enc_idx
, 0),
2837 IOCTL_INFO(VIDIOC_ENCODER_CMD
, v4l_stub_encoder_cmd
, v4l_print_encoder_cmd
, INFO_FL_PRIO
| INFO_FL_CLEAR(v4l2_encoder_cmd
, flags
)),
2838 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD
, v4l_stub_try_encoder_cmd
, v4l_print_encoder_cmd
, INFO_FL_CLEAR(v4l2_encoder_cmd
, flags
)),
2839 IOCTL_INFO(VIDIOC_DECODER_CMD
, v4l_stub_decoder_cmd
, v4l_print_decoder_cmd
, INFO_FL_PRIO
),
2840 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD
, v4l_stub_try_decoder_cmd
, v4l_print_decoder_cmd
, 0),
2841 IOCTL_INFO(VIDIOC_DBG_S_REGISTER
, v4l_dbg_s_register
, v4l_print_dbg_register
, 0),
2842 IOCTL_INFO(VIDIOC_DBG_G_REGISTER
, v4l_dbg_g_register
, v4l_print_dbg_register
, 0),
2843 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK
, v4l_s_hw_freq_seek
, v4l_print_hw_freq_seek
, INFO_FL_PRIO
),
2844 IOCTL_INFO(VIDIOC_S_DV_TIMINGS
, v4l_stub_s_dv_timings
, v4l_print_dv_timings
, INFO_FL_PRIO
| INFO_FL_CLEAR(v4l2_dv_timings
, bt
.flags
)),
2845 IOCTL_INFO(VIDIOC_G_DV_TIMINGS
, v4l_stub_g_dv_timings
, v4l_print_dv_timings
, 0),
2846 IOCTL_INFO(VIDIOC_DQEVENT
, v4l_dqevent
, v4l_print_event
, 0),
2847 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT
, v4l_subscribe_event
, v4l_print_event_subscription
, 0),
2848 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT
, v4l_unsubscribe_event
, v4l_print_event_subscription
, 0),
2849 IOCTL_INFO(VIDIOC_CREATE_BUFS
, v4l_create_bufs
, v4l_print_create_buffers
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2850 IOCTL_INFO(VIDIOC_PREPARE_BUF
, v4l_prepare_buf
, v4l_print_buffer
, INFO_FL_QUEUE
),
2851 IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS
, v4l_stub_enum_dv_timings
, v4l_print_enum_dv_timings
, INFO_FL_CLEAR(v4l2_enum_dv_timings
, pad
)),
2852 IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS
, v4l_stub_query_dv_timings
, v4l_print_dv_timings
, INFO_FL_ALWAYS_COPY
),
2853 IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP
, v4l_stub_dv_timings_cap
, v4l_print_dv_timings_cap
, INFO_FL_CLEAR(v4l2_dv_timings_cap
, pad
)),
2854 IOCTL_INFO(VIDIOC_ENUM_FREQ_BANDS
, v4l_enum_freq_bands
, v4l_print_freq_band
, 0),
2855 IOCTL_INFO(VIDIOC_DBG_G_CHIP_INFO
, v4l_dbg_g_chip_info
, v4l_print_dbg_chip_info
, INFO_FL_CLEAR(v4l2_dbg_chip_info
, match
)),
2856 IOCTL_INFO(VIDIOC_QUERY_EXT_CTRL
, v4l_query_ext_ctrl
, v4l_print_query_ext_ctrl
, INFO_FL_CTRL
| INFO_FL_CLEAR(v4l2_query_ext_ctrl
, id
)),
2858 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
2860 static bool v4l2_is_known_ioctl(unsigned int cmd
)
2862 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
)
2864 return v4l2_ioctls
[_IOC_NR(cmd
)].ioctl
== cmd
;
2867 static struct mutex
*v4l2_ioctl_get_lock(struct video_device
*vdev
,
2868 struct v4l2_fh
*vfh
, unsigned int cmd
,
2871 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
)
2873 if (vfh
&& vfh
->m2m_ctx
&&
2874 (v4l2_ioctls
[_IOC_NR(cmd
)].flags
& INFO_FL_QUEUE
)) {
2875 if (vfh
->m2m_ctx
->q_lock
)
2876 return vfh
->m2m_ctx
->q_lock
;
2878 if (vdev
->queue
&& vdev
->queue
->lock
&&
2879 (v4l2_ioctls
[_IOC_NR(cmd
)].flags
& INFO_FL_QUEUE
))
2880 return vdev
->queue
->lock
;
2884 /* Common ioctl debug function. This function can be used by
2885 external ioctl messages as well as internal V4L ioctl */
2886 void v4l_printk_ioctl(const char *prefix
, unsigned int cmd
)
2888 const char *dir
, *type
;
2891 printk(KERN_DEBUG
"%s: ", prefix
);
2893 switch (_IOC_TYPE(cmd
)) {
2898 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
2902 pr_cont("%s", v4l2_ioctls
[_IOC_NR(cmd
)].name
);
2909 switch (_IOC_DIR(cmd
)) {
2910 case _IOC_NONE
: dir
= "--"; break;
2911 case _IOC_READ
: dir
= "r-"; break;
2912 case _IOC_WRITE
: dir
= "-w"; break;
2913 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
2914 default: dir
= "*ERR*"; break;
2916 pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
2917 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
2919 EXPORT_SYMBOL(v4l_printk_ioctl
);
2921 static long __video_do_ioctl(struct file
*file
,
2922 unsigned int cmd
, void *arg
)
2924 struct video_device
*vfd
= video_devdata(file
);
2925 struct mutex
*req_queue_lock
= NULL
;
2926 struct mutex
*lock
; /* ioctl serialization mutex */
2927 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
2928 bool write_only
= false;
2929 struct v4l2_ioctl_info default_info
;
2930 const struct v4l2_ioctl_info
*info
;
2931 void *fh
= file
->private_data
;
2932 struct v4l2_fh
*vfh
= NULL
;
2933 int dev_debug
= vfd
->dev_debug
;
2937 pr_warn("%s: has no ioctl_ops.\n",
2938 video_device_node_name(vfd
));
2942 if (test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
))
2943 vfh
= file
->private_data
;
2946 * We need to serialize streamon/off with queueing new requests.
2947 * These ioctls may trigger the cancellation of a streaming
2948 * operation, and that should not be mixed with queueing a new
2949 * request at the same time.
2951 if (v4l2_device_supports_requests(vfd
->v4l2_dev
) &&
2952 (cmd
== VIDIOC_STREAMON
|| cmd
== VIDIOC_STREAMOFF
)) {
2953 req_queue_lock
= &vfd
->v4l2_dev
->mdev
->req_queue_mutex
;
2955 if (mutex_lock_interruptible(req_queue_lock
))
2956 return -ERESTARTSYS
;
2959 lock
= v4l2_ioctl_get_lock(vfd
, vfh
, cmd
, arg
);
2961 if (lock
&& mutex_lock_interruptible(lock
)) {
2963 mutex_unlock(req_queue_lock
);
2964 return -ERESTARTSYS
;
2967 if (!video_is_registered(vfd
)) {
2972 if (v4l2_is_known_ioctl(cmd
)) {
2973 info
= &v4l2_ioctls
[_IOC_NR(cmd
)];
2975 if (!test_bit(_IOC_NR(cmd
), vfd
->valid_ioctls
) &&
2976 !((info
->flags
& INFO_FL_CTRL
) && vfh
&& vfh
->ctrl_handler
))
2979 if (vfh
&& (info
->flags
& INFO_FL_PRIO
)) {
2980 ret
= v4l2_prio_check(vfd
->prio
, vfh
->prio
);
2985 default_info
.ioctl
= cmd
;
2986 default_info
.flags
= 0;
2987 default_info
.debug
= v4l_print_default
;
2988 info
= &default_info
;
2991 write_only
= _IOC_DIR(cmd
) == _IOC_WRITE
;
2992 if (info
!= &default_info
) {
2993 ret
= info
->func(ops
, file
, fh
, arg
);
2994 } else if (!ops
->vidioc_default
) {
2997 ret
= ops
->vidioc_default(file
, fh
,
2998 vfh
? v4l2_prio_check(vfd
->prio
, vfh
->prio
) >= 0 : 0,
3003 if (dev_debug
& (V4L2_DEV_DEBUG_IOCTL
| V4L2_DEV_DEBUG_IOCTL_ARG
)) {
3004 if (!(dev_debug
& V4L2_DEV_DEBUG_STREAMING
) &&
3005 (cmd
== VIDIOC_QBUF
|| cmd
== VIDIOC_DQBUF
))
3008 v4l_printk_ioctl(video_device_node_name(vfd
), cmd
);
3010 pr_cont(": error %ld", ret
);
3011 if (!(dev_debug
& V4L2_DEV_DEBUG_IOCTL_ARG
))
3013 else if (_IOC_DIR(cmd
) == _IOC_NONE
)
3014 info
->debug(arg
, write_only
);
3017 info
->debug(arg
, write_only
);
3025 mutex_unlock(req_queue_lock
);
3029 static int check_array_args(unsigned int cmd
, void *parg
, size_t *array_size
,
3030 void __user
**user_ptr
, void ***kernel_ptr
)
3035 case VIDIOC_PREPARE_BUF
:
3036 case VIDIOC_QUERYBUF
:
3038 case VIDIOC_DQBUF
: {
3039 struct v4l2_buffer
*buf
= parg
;
3041 if (V4L2_TYPE_IS_MULTIPLANAR(buf
->type
) && buf
->length
> 0) {
3042 if (buf
->length
> VIDEO_MAX_PLANES
) {
3046 *user_ptr
= (void __user
*)buf
->m
.planes
;
3047 *kernel_ptr
= (void **)&buf
->m
.planes
;
3048 *array_size
= sizeof(struct v4l2_plane
) * buf
->length
;
3055 case VIDIOC_S_EDID
: {
3056 struct v4l2_edid
*edid
= parg
;
3059 if (edid
->blocks
> 256) {
3063 *user_ptr
= (void __user
*)edid
->edid
;
3064 *kernel_ptr
= (void **)&edid
->edid
;
3065 *array_size
= edid
->blocks
* 128;
3071 case VIDIOC_S_EXT_CTRLS
:
3072 case VIDIOC_G_EXT_CTRLS
:
3073 case VIDIOC_TRY_EXT_CTRLS
: {
3074 struct v4l2_ext_controls
*ctrls
= parg
;
3076 if (ctrls
->count
!= 0) {
3077 if (ctrls
->count
> V4L2_CID_MAX_CTRLS
) {
3081 *user_ptr
= (void __user
*)ctrls
->controls
;
3082 *kernel_ptr
= (void **)&ctrls
->controls
;
3083 *array_size
= sizeof(struct v4l2_ext_control
)
3091 case VIDIOC_TRY_FMT
: {
3092 struct v4l2_format
*fmt
= parg
;
3094 if (fmt
->type
!= V4L2_BUF_TYPE_VIDEO_OVERLAY
&&
3095 fmt
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
)
3097 if (fmt
->fmt
.win
.clipcount
> 2048)
3099 if (!fmt
->fmt
.win
.clipcount
)
3102 *user_ptr
= (void __user
*)fmt
->fmt
.win
.clips
;
3103 *kernel_ptr
= (void **)&fmt
->fmt
.win
.clips
;
3104 *array_size
= sizeof(struct v4l2_clip
)
3105 * fmt
->fmt
.win
.clipcount
;
3115 static unsigned int video_translate_cmd(unsigned int cmd
)
3118 #ifdef CONFIG_COMPAT_32BIT_TIME
3119 case VIDIOC_DQEVENT_TIME32
:
3120 return VIDIOC_DQEVENT
;
3121 case VIDIOC_QUERYBUF_TIME32
:
3122 return VIDIOC_QUERYBUF
;
3123 case VIDIOC_QBUF_TIME32
:
3125 case VIDIOC_DQBUF_TIME32
:
3126 return VIDIOC_DQBUF
;
3127 case VIDIOC_PREPARE_BUF_TIME32
:
3128 return VIDIOC_PREPARE_BUF
;
3131 if (in_compat_syscall())
3132 return v4l2_compat_translate_cmd(cmd
);
3137 static int video_get_user(void __user
*arg
, void *parg
,
3138 unsigned int real_cmd
, unsigned int cmd
,
3141 unsigned int n
= _IOC_SIZE(real_cmd
);
3144 if (!(_IOC_DIR(cmd
) & _IOC_WRITE
)) {
3145 /* read-only ioctl */
3151 * In some cases, only a few fields are used as input,
3152 * i.e. when the app sets "index" and then the driver
3153 * fills in the rest of the structure for the thing
3154 * with that index. We only need to copy up the first
3157 if (v4l2_is_known_ioctl(real_cmd
)) {
3158 u32 flags
= v4l2_ioctls
[_IOC_NR(real_cmd
)].flags
;
3160 if (flags
& INFO_FL_CLEAR_MASK
)
3161 n
= (flags
& INFO_FL_CLEAR_MASK
) >> 16;
3162 *always_copy
= flags
& INFO_FL_ALWAYS_COPY
;
3165 if (cmd
== real_cmd
) {
3166 if (copy_from_user(parg
, (void __user
*)arg
, n
))
3168 } else if (in_compat_syscall()) {
3169 err
= v4l2_compat_get_user(arg
, parg
, cmd
);
3172 #ifdef CONFIG_COMPAT_32BIT_TIME
3173 case VIDIOC_QUERYBUF_TIME32
:
3174 case VIDIOC_QBUF_TIME32
:
3175 case VIDIOC_DQBUF_TIME32
:
3176 case VIDIOC_PREPARE_BUF_TIME32
: {
3177 struct v4l2_buffer_time32 vb32
;
3178 struct v4l2_buffer
*vb
= parg
;
3180 if (copy_from_user(&vb32
, arg
, sizeof(vb32
)))
3183 *vb
= (struct v4l2_buffer
) {
3184 .index
= vb32
.index
,
3186 .bytesused
= vb32
.bytesused
,
3187 .flags
= vb32
.flags
,
3188 .field
= vb32
.field
,
3189 .timestamp
.tv_sec
= vb32
.timestamp
.tv_sec
,
3190 .timestamp
.tv_usec
= vb32
.timestamp
.tv_usec
,
3191 .timecode
= vb32
.timecode
,
3192 .sequence
= vb32
.sequence
,
3193 .memory
= vb32
.memory
,
3194 .m
.userptr
= vb32
.m
.userptr
,
3195 .length
= vb32
.length
,
3196 .request_fd
= vb32
.request_fd
,
3204 /* zero out anything we don't copy from userspace */
3205 if (!err
&& n
< _IOC_SIZE(real_cmd
))
3206 memset((u8
*)parg
+ n
, 0, _IOC_SIZE(real_cmd
) - n
);
3210 static int video_put_user(void __user
*arg
, void *parg
,
3211 unsigned int real_cmd
, unsigned int cmd
)
3213 if (!(_IOC_DIR(cmd
) & _IOC_READ
))
3216 if (cmd
== real_cmd
) {
3217 /* Copy results into user buffer */
3218 if (copy_to_user(arg
, parg
, _IOC_SIZE(cmd
)))
3223 if (in_compat_syscall())
3224 return v4l2_compat_put_user(arg
, parg
, cmd
);
3227 #ifdef CONFIG_COMPAT_32BIT_TIME
3228 case VIDIOC_DQEVENT_TIME32
: {
3229 struct v4l2_event
*ev
= parg
;
3230 struct v4l2_event_time32 ev32
;
3232 memset(&ev32
, 0, sizeof(ev32
));
3234 ev32
.type
= ev
->type
;
3235 ev32
.pending
= ev
->pending
;
3236 ev32
.sequence
= ev
->sequence
;
3237 ev32
.timestamp
.tv_sec
= ev
->timestamp
.tv_sec
;
3238 ev32
.timestamp
.tv_nsec
= ev
->timestamp
.tv_nsec
;
3241 memcpy(&ev32
.u
, &ev
->u
, sizeof(ev
->u
));
3242 memcpy(&ev32
.reserved
, &ev
->reserved
, sizeof(ev
->reserved
));
3244 if (copy_to_user(arg
, &ev32
, sizeof(ev32
)))
3248 case VIDIOC_QUERYBUF_TIME32
:
3249 case VIDIOC_QBUF_TIME32
:
3250 case VIDIOC_DQBUF_TIME32
:
3251 case VIDIOC_PREPARE_BUF_TIME32
: {
3252 struct v4l2_buffer
*vb
= parg
;
3253 struct v4l2_buffer_time32 vb32
;
3255 memset(&vb32
, 0, sizeof(vb32
));
3257 vb32
.index
= vb
->index
;
3258 vb32
.type
= vb
->type
;
3259 vb32
.bytesused
= vb
->bytesused
;
3260 vb32
.flags
= vb
->flags
;
3261 vb32
.field
= vb
->field
;
3262 vb32
.timestamp
.tv_sec
= vb
->timestamp
.tv_sec
;
3263 vb32
.timestamp
.tv_usec
= vb
->timestamp
.tv_usec
;
3264 vb32
.timecode
= vb
->timecode
;
3265 vb32
.sequence
= vb
->sequence
;
3266 vb32
.memory
= vb
->memory
;
3267 vb32
.m
.userptr
= vb
->m
.userptr
;
3268 vb32
.length
= vb
->length
;
3269 vb32
.request_fd
= vb
->request_fd
;
3271 if (copy_to_user(arg
, &vb32
, sizeof(vb32
)))
3282 video_usercopy(struct file
*file
, unsigned int orig_cmd
, unsigned long arg
,
3287 void *parg
= (void *)arg
;
3289 bool has_array_args
;
3290 bool always_copy
= false;
3291 size_t array_size
= 0;
3292 void __user
*user_ptr
= NULL
;
3293 void **kernel_ptr
= NULL
;
3294 unsigned int cmd
= video_translate_cmd(orig_cmd
);
3295 const size_t ioc_size
= _IOC_SIZE(cmd
);
3297 /* Copy arguments into temp kernel buffer */
3298 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
3299 if (ioc_size
<= sizeof(sbuf
)) {
3302 /* too big to allocate from stack */
3303 mbuf
= kvmalloc(ioc_size
, GFP_KERNEL
);
3309 err
= video_get_user((void __user
*)arg
, parg
, cmd
,
3310 orig_cmd
, &always_copy
);
3315 err
= check_array_args(cmd
, parg
, &array_size
, &user_ptr
, &kernel_ptr
);
3318 has_array_args
= err
;
3320 if (has_array_args
) {
3322 * When adding new types of array args, make sure that the
3323 * parent argument to ioctl (which contains the pointer to the
3324 * array) fits into sbuf (so that mbuf will still remain
3325 * unused up to here).
3327 mbuf
= kvmalloc(array_size
, GFP_KERNEL
);
3330 goto out_array_args
;
3332 if (in_compat_syscall())
3333 err
= v4l2_compat_get_array_args(file
, mbuf
, user_ptr
,
3334 array_size
, orig_cmd
,
3337 err
= copy_from_user(mbuf
, user_ptr
, array_size
) ?
3340 goto out_array_args
;
3345 err
= func(file
, cmd
, parg
);
3346 if (err
== -ENOTTY
|| err
== -ENOIOCTLCMD
) {
3352 if (cmd
== VIDIOC_DQBUF
)
3353 trace_v4l2_dqbuf(video_devdata(file
)->minor
, parg
);
3354 else if (cmd
== VIDIOC_QBUF
)
3355 trace_v4l2_qbuf(video_devdata(file
)->minor
, parg
);
3358 if (has_array_args
) {
3359 *kernel_ptr
= (void __force
*)user_ptr
;
3360 if (in_compat_syscall()) {
3363 put_err
= v4l2_compat_put_array_args(file
, user_ptr
, mbuf
,
3364 array_size
, orig_cmd
,
3368 } else if (copy_to_user(user_ptr
, mbuf
, array_size
)) {
3371 goto out_array_args
;
3374 * Some ioctls can return an error, but still have valid
3375 * results that must be returned.
3377 if (err
< 0 && !always_copy
)
3381 if (video_put_user((void __user
*)arg
, parg
, cmd
, orig_cmd
))
3388 long video_ioctl2(struct file
*file
,
3389 unsigned int cmd
, unsigned long arg
)
3391 return video_usercopy(file
, cmd
, arg
, __video_do_ioctl
);
3393 EXPORT_SYMBOL(video_ioctl2
);