2 * Video capture interface for Linux version 2
4 * A generic framework to process V4L2 ioctl commands.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
12 * Mauro Carvalho Chehab <mchehab@kernel.org> (version 2)
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/types.h>
19 #include <linux/kernel.h>
20 #include <linux/version.h>
22 #include <linux/videodev2.h>
24 #include <media/v4l2-common.h>
25 #include <media/v4l2-ioctl.h>
26 #include <media/v4l2-ctrls.h>
27 #include <media/v4l2-fh.h>
28 #include <media/v4l2-event.h>
29 #include <media/v4l2-device.h>
30 #include <media/videobuf2-v4l2.h>
31 #include <media/v4l2-mc.h>
32 #include <media/v4l2-mem2mem.h>
34 #include <trace/events/v4l2.h>
36 /* Zero out the end of the struct pointed to by p. Everything after, but
37 * not including, the specified field is cleared. */
38 #define CLEAR_AFTER_FIELD(p, field) \
39 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
40 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
42 #define is_valid_ioctl(vfd, cmd) test_bit(_IOC_NR(cmd), (vfd)->valid_ioctls)
49 static const struct std_descr standards
[] = {
50 { V4L2_STD_NTSC
, "NTSC" },
51 { V4L2_STD_NTSC_M
, "NTSC-M" },
52 { V4L2_STD_NTSC_M_JP
, "NTSC-M-JP" },
53 { V4L2_STD_NTSC_M_KR
, "NTSC-M-KR" },
54 { V4L2_STD_NTSC_443
, "NTSC-443" },
55 { V4L2_STD_PAL
, "PAL" },
56 { V4L2_STD_PAL_BG
, "PAL-BG" },
57 { V4L2_STD_PAL_B
, "PAL-B" },
58 { V4L2_STD_PAL_B1
, "PAL-B1" },
59 { V4L2_STD_PAL_G
, "PAL-G" },
60 { V4L2_STD_PAL_H
, "PAL-H" },
61 { V4L2_STD_PAL_I
, "PAL-I" },
62 { V4L2_STD_PAL_DK
, "PAL-DK" },
63 { V4L2_STD_PAL_D
, "PAL-D" },
64 { V4L2_STD_PAL_D1
, "PAL-D1" },
65 { V4L2_STD_PAL_K
, "PAL-K" },
66 { V4L2_STD_PAL_M
, "PAL-M" },
67 { V4L2_STD_PAL_N
, "PAL-N" },
68 { V4L2_STD_PAL_Nc
, "PAL-Nc" },
69 { V4L2_STD_PAL_60
, "PAL-60" },
70 { V4L2_STD_SECAM
, "SECAM" },
71 { V4L2_STD_SECAM_B
, "SECAM-B" },
72 { V4L2_STD_SECAM_G
, "SECAM-G" },
73 { V4L2_STD_SECAM_H
, "SECAM-H" },
74 { V4L2_STD_SECAM_DK
, "SECAM-DK" },
75 { V4L2_STD_SECAM_D
, "SECAM-D" },
76 { V4L2_STD_SECAM_K
, "SECAM-K" },
77 { V4L2_STD_SECAM_K1
, "SECAM-K1" },
78 { V4L2_STD_SECAM_L
, "SECAM-L" },
79 { V4L2_STD_SECAM_LC
, "SECAM-Lc" },
83 /* video4linux standard ID conversion to standard name
85 const char *v4l2_norm_to_name(v4l2_std_id id
)
90 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
91 64 bit comparations. So, on that architecture, with some gcc
92 variants, compilation fails. Currently, the max value is 30bit wide.
96 for (i
= 0; standards
[i
].std
; i
++)
97 if (myid
== standards
[i
].std
)
99 return standards
[i
].descr
;
101 EXPORT_SYMBOL(v4l2_norm_to_name
);
103 /* Returns frame period for the given standard */
104 void v4l2_video_std_frame_period(int id
, struct v4l2_fract
*frameperiod
)
106 if (id
& V4L2_STD_525_60
) {
107 frameperiod
->numerator
= 1001;
108 frameperiod
->denominator
= 30000;
110 frameperiod
->numerator
= 1;
111 frameperiod
->denominator
= 25;
114 EXPORT_SYMBOL(v4l2_video_std_frame_period
);
116 /* Fill in the fields of a v4l2_standard structure according to the
117 'id' and 'transmission' parameters. Returns negative on error. */
118 int v4l2_video_std_construct(struct v4l2_standard
*vs
,
119 int id
, const char *name
)
122 v4l2_video_std_frame_period(id
, &vs
->frameperiod
);
123 vs
->framelines
= (id
& V4L2_STD_525_60
) ? 525 : 625;
124 strscpy(vs
->name
, name
, sizeof(vs
->name
));
127 EXPORT_SYMBOL(v4l2_video_std_construct
);
129 /* Fill in the fields of a v4l2_standard structure according to the
130 * 'id' and 'vs->index' parameters. Returns negative on error. */
131 int v4l_video_std_enumstd(struct v4l2_standard
*vs
, v4l2_std_id id
)
133 v4l2_std_id curr_id
= 0;
134 unsigned int index
= vs
->index
, i
, j
= 0;
135 const char *descr
= "";
137 /* Return -ENODATA if the id for the current input
138 or output is 0, meaning that it doesn't support this API. */
142 /* Return norm array in a canonical way */
143 for (i
= 0; i
<= index
&& id
; i
++) {
144 /* last std value in the standards array is 0, so this
145 while always ends there since (id & 0) == 0. */
146 while ((id
& standards
[j
].std
) != standards
[j
].std
)
148 curr_id
= standards
[j
].std
;
149 descr
= standards
[j
].descr
;
153 if (curr_id
!= V4L2_STD_PAL
&&
154 curr_id
!= V4L2_STD_SECAM
&&
155 curr_id
!= V4L2_STD_NTSC
)
161 v4l2_video_std_construct(vs
, curr_id
, descr
);
165 /* ----------------------------------------------------------------- */
166 /* some arrays for pretty-printing debug messages of enum types */
168 const char *v4l2_field_names
[] = {
169 [V4L2_FIELD_ANY
] = "any",
170 [V4L2_FIELD_NONE
] = "none",
171 [V4L2_FIELD_TOP
] = "top",
172 [V4L2_FIELD_BOTTOM
] = "bottom",
173 [V4L2_FIELD_INTERLACED
] = "interlaced",
174 [V4L2_FIELD_SEQ_TB
] = "seq-tb",
175 [V4L2_FIELD_SEQ_BT
] = "seq-bt",
176 [V4L2_FIELD_ALTERNATE
] = "alternate",
177 [V4L2_FIELD_INTERLACED_TB
] = "interlaced-tb",
178 [V4L2_FIELD_INTERLACED_BT
] = "interlaced-bt",
180 EXPORT_SYMBOL(v4l2_field_names
);
182 const char *v4l2_type_names
[] = {
184 [V4L2_BUF_TYPE_VIDEO_CAPTURE
] = "vid-cap",
185 [V4L2_BUF_TYPE_VIDEO_OVERLAY
] = "vid-overlay",
186 [V4L2_BUF_TYPE_VIDEO_OUTPUT
] = "vid-out",
187 [V4L2_BUF_TYPE_VBI_CAPTURE
] = "vbi-cap",
188 [V4L2_BUF_TYPE_VBI_OUTPUT
] = "vbi-out",
189 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
] = "sliced-vbi-cap",
190 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
] = "sliced-vbi-out",
191 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
] = "vid-out-overlay",
192 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
] = "vid-cap-mplane",
193 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
] = "vid-out-mplane",
194 [V4L2_BUF_TYPE_SDR_CAPTURE
] = "sdr-cap",
195 [V4L2_BUF_TYPE_SDR_OUTPUT
] = "sdr-out",
196 [V4L2_BUF_TYPE_META_CAPTURE
] = "meta-cap",
197 [V4L2_BUF_TYPE_META_OUTPUT
] = "meta-out",
199 EXPORT_SYMBOL(v4l2_type_names
);
201 static const char *v4l2_memory_names
[] = {
202 [V4L2_MEMORY_MMAP
] = "mmap",
203 [V4L2_MEMORY_USERPTR
] = "userptr",
204 [V4L2_MEMORY_OVERLAY
] = "overlay",
205 [V4L2_MEMORY_DMABUF
] = "dmabuf",
208 #define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown")
210 /* ------------------------------------------------------------------ */
211 /* debug help functions */
213 static void v4l_print_querycap(const void *arg
, bool write_only
)
215 const struct v4l2_capability
*p
= arg
;
217 pr_cont("driver=%.*s, card=%.*s, bus=%.*s, version=0x%08x, capabilities=0x%08x, device_caps=0x%08x\n",
218 (int)sizeof(p
->driver
), p
->driver
,
219 (int)sizeof(p
->card
), p
->card
,
220 (int)sizeof(p
->bus_info
), p
->bus_info
,
221 p
->version
, p
->capabilities
, p
->device_caps
);
224 static void v4l_print_enuminput(const void *arg
, bool write_only
)
226 const struct v4l2_input
*p
= arg
;
228 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, tuner=%u, std=0x%08Lx, status=0x%x, capabilities=0x%x\n",
229 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->type
, p
->audioset
,
230 p
->tuner
, (unsigned long long)p
->std
, p
->status
,
234 static void v4l_print_enumoutput(const void *arg
, bool write_only
)
236 const struct v4l2_output
*p
= arg
;
238 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, modulator=%u, std=0x%08Lx, capabilities=0x%x\n",
239 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->type
, p
->audioset
,
240 p
->modulator
, (unsigned long long)p
->std
, p
->capabilities
);
243 static void v4l_print_audio(const void *arg
, bool write_only
)
245 const struct v4l2_audio
*p
= arg
;
248 pr_cont("index=%u, mode=0x%x\n", p
->index
, p
->mode
);
250 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
251 p
->index
, (int)sizeof(p
->name
), p
->name
,
252 p
->capability
, p
->mode
);
255 static void v4l_print_audioout(const void *arg
, bool write_only
)
257 const struct v4l2_audioout
*p
= arg
;
260 pr_cont("index=%u\n", p
->index
);
262 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
263 p
->index
, (int)sizeof(p
->name
), p
->name
,
264 p
->capability
, p
->mode
);
267 static void v4l_print_fmtdesc(const void *arg
, bool write_only
)
269 const struct v4l2_fmtdesc
*p
= arg
;
271 pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%.*s'\n",
272 p
->index
, prt_names(p
->type
, v4l2_type_names
),
273 p
->flags
, (p
->pixelformat
& 0xff),
274 (p
->pixelformat
>> 8) & 0xff,
275 (p
->pixelformat
>> 16) & 0xff,
276 (p
->pixelformat
>> 24) & 0xff,
277 (int)sizeof(p
->description
), p
->description
);
280 static void v4l_print_format(const void *arg
, bool write_only
)
282 const struct v4l2_format
*p
= arg
;
283 const struct v4l2_pix_format
*pix
;
284 const struct v4l2_pix_format_mplane
*mp
;
285 const struct v4l2_vbi_format
*vbi
;
286 const struct v4l2_sliced_vbi_format
*sliced
;
287 const struct v4l2_window
*win
;
288 const struct v4l2_sdr_format
*sdr
;
289 const struct v4l2_meta_format
*meta
;
293 pr_cont("type=%s", prt_names(p
->type
, v4l2_type_names
));
295 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
296 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
298 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",
299 pix
->width
, pix
->height
,
300 (pix
->pixelformat
& 0xff),
301 (pix
->pixelformat
>> 8) & 0xff,
302 (pix
->pixelformat
>> 16) & 0xff,
303 (pix
->pixelformat
>> 24) & 0xff,
304 prt_names(pix
->field
, v4l2_field_names
),
305 pix
->bytesperline
, pix
->sizeimage
,
306 pix
->colorspace
, pix
->flags
, pix
->ycbcr_enc
,
307 pix
->quantization
, pix
->xfer_func
);
309 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
310 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
312 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",
313 mp
->width
, mp
->height
,
314 (mp
->pixelformat
& 0xff),
315 (mp
->pixelformat
>> 8) & 0xff,
316 (mp
->pixelformat
>> 16) & 0xff,
317 (mp
->pixelformat
>> 24) & 0xff,
318 prt_names(mp
->field
, v4l2_field_names
),
319 mp
->colorspace
, mp
->num_planes
, mp
->flags
,
320 mp
->ycbcr_enc
, mp
->quantization
, mp
->xfer_func
);
321 planes
= min_t(u32
, mp
->num_planes
, VIDEO_MAX_PLANES
);
322 for (i
= 0; i
< planes
; i
++)
323 printk(KERN_DEBUG
"plane %u: bytesperline=%u sizeimage=%u\n", i
,
324 mp
->plane_fmt
[i
].bytesperline
,
325 mp
->plane_fmt
[i
].sizeimage
);
327 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
328 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
330 /* Note: we can't print the clip list here since the clips
331 * pointer is a userspace pointer, not a kernelspace
333 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",
334 win
->w
.width
, win
->w
.height
, win
->w
.left
, win
->w
.top
,
335 prt_names(win
->field
, v4l2_field_names
),
336 win
->chromakey
, win
->clipcount
, win
->clips
,
337 win
->bitmap
, win
->global_alpha
);
339 case V4L2_BUF_TYPE_VBI_CAPTURE
:
340 case V4L2_BUF_TYPE_VBI_OUTPUT
:
342 pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, sample_format=%c%c%c%c, start=%u,%u, count=%u,%u\n",
343 vbi
->sampling_rate
, vbi
->offset
,
344 vbi
->samples_per_line
,
345 (vbi
->sample_format
& 0xff),
346 (vbi
->sample_format
>> 8) & 0xff,
347 (vbi
->sample_format
>> 16) & 0xff,
348 (vbi
->sample_format
>> 24) & 0xff,
349 vbi
->start
[0], vbi
->start
[1],
350 vbi
->count
[0], vbi
->count
[1]);
352 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
353 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
354 sliced
= &p
->fmt
.sliced
;
355 pr_cont(", service_set=0x%08x, io_size=%d\n",
356 sliced
->service_set
, sliced
->io_size
);
357 for (i
= 0; i
< 24; i
++)
358 printk(KERN_DEBUG
"line[%02u]=0x%04x, 0x%04x\n", i
,
359 sliced
->service_lines
[0][i
],
360 sliced
->service_lines
[1][i
]);
362 case V4L2_BUF_TYPE_SDR_CAPTURE
:
363 case V4L2_BUF_TYPE_SDR_OUTPUT
:
365 pr_cont(", pixelformat=%c%c%c%c\n",
366 (sdr
->pixelformat
>> 0) & 0xff,
367 (sdr
->pixelformat
>> 8) & 0xff,
368 (sdr
->pixelformat
>> 16) & 0xff,
369 (sdr
->pixelformat
>> 24) & 0xff);
371 case V4L2_BUF_TYPE_META_CAPTURE
:
372 case V4L2_BUF_TYPE_META_OUTPUT
:
374 pr_cont(", dataformat=%c%c%c%c, buffersize=%u\n",
375 (meta
->dataformat
>> 0) & 0xff,
376 (meta
->dataformat
>> 8) & 0xff,
377 (meta
->dataformat
>> 16) & 0xff,
378 (meta
->dataformat
>> 24) & 0xff,
384 static void v4l_print_framebuffer(const void *arg
, bool write_only
)
386 const struct v4l2_framebuffer
*p
= arg
;
388 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",
389 p
->capability
, p
->flags
, p
->base
,
390 p
->fmt
.width
, p
->fmt
.height
,
391 (p
->fmt
.pixelformat
& 0xff),
392 (p
->fmt
.pixelformat
>> 8) & 0xff,
393 (p
->fmt
.pixelformat
>> 16) & 0xff,
394 (p
->fmt
.pixelformat
>> 24) & 0xff,
395 p
->fmt
.bytesperline
, p
->fmt
.sizeimage
,
399 static void v4l_print_buftype(const void *arg
, bool write_only
)
401 pr_cont("type=%s\n", prt_names(*(u32
*)arg
, v4l2_type_names
));
404 static void v4l_print_modulator(const void *arg
, bool write_only
)
406 const struct v4l2_modulator
*p
= arg
;
409 pr_cont("index=%u, txsubchans=0x%x\n", p
->index
, p
->txsubchans
);
411 pr_cont("index=%u, name=%.*s, capability=0x%x, rangelow=%u, rangehigh=%u, txsubchans=0x%x\n",
412 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->capability
,
413 p
->rangelow
, p
->rangehigh
, p
->txsubchans
);
416 static void v4l_print_tuner(const void *arg
, bool write_only
)
418 const struct v4l2_tuner
*p
= arg
;
421 pr_cont("index=%u, audmode=%u\n", p
->index
, p
->audmode
);
423 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",
424 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->type
,
425 p
->capability
, p
->rangelow
,
426 p
->rangehigh
, p
->signal
, p
->afc
,
427 p
->rxsubchans
, p
->audmode
);
430 static void v4l_print_frequency(const void *arg
, bool write_only
)
432 const struct v4l2_frequency
*p
= arg
;
434 pr_cont("tuner=%u, type=%u, frequency=%u\n",
435 p
->tuner
, p
->type
, p
->frequency
);
438 static void v4l_print_standard(const void *arg
, bool write_only
)
440 const struct v4l2_standard
*p
= arg
;
442 pr_cont("index=%u, id=0x%Lx, name=%.*s, fps=%u/%u, framelines=%u\n",
444 (unsigned long long)p
->id
, (int)sizeof(p
->name
), p
->name
,
445 p
->frameperiod
.numerator
,
446 p
->frameperiod
.denominator
,
450 static void v4l_print_std(const void *arg
, bool write_only
)
452 pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg
);
455 static void v4l_print_hw_freq_seek(const void *arg
, bool write_only
)
457 const struct v4l2_hw_freq_seek
*p
= arg
;
459 pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u, rangelow=%u, rangehigh=%u\n",
460 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
, p
->spacing
,
461 p
->rangelow
, p
->rangehigh
);
464 static void v4l_print_requestbuffers(const void *arg
, bool write_only
)
466 const struct v4l2_requestbuffers
*p
= arg
;
468 pr_cont("count=%d, type=%s, memory=%s\n",
470 prt_names(p
->type
, v4l2_type_names
),
471 prt_names(p
->memory
, v4l2_memory_names
));
474 static void v4l_print_buffer(const void *arg
, bool write_only
)
476 const struct v4l2_buffer
*p
= arg
;
477 const struct v4l2_timecode
*tc
= &p
->timecode
;
478 const struct v4l2_plane
*plane
;
481 pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, request_fd=%d, flags=0x%08x, field=%s, sequence=%d, memory=%s",
482 p
->timestamp
.tv_sec
/ 3600,
483 (int)(p
->timestamp
.tv_sec
/ 60) % 60,
484 (int)(p
->timestamp
.tv_sec
% 60),
485 (long)p
->timestamp
.tv_usec
,
487 prt_names(p
->type
, v4l2_type_names
), p
->request_fd
,
488 p
->flags
, prt_names(p
->field
, v4l2_field_names
),
489 p
->sequence
, prt_names(p
->memory
, v4l2_memory_names
));
491 if (V4L2_TYPE_IS_MULTIPLANAR(p
->type
) && p
->m
.planes
) {
493 for (i
= 0; i
< p
->length
; ++i
) {
494 plane
= &p
->m
.planes
[i
];
496 "plane %d: bytesused=%d, data_offset=0x%08x, offset/userptr=0x%lx, length=%d\n",
497 i
, plane
->bytesused
, plane
->data_offset
,
498 plane
->m
.userptr
, plane
->length
);
501 pr_cont(", bytesused=%d, offset/userptr=0x%lx, length=%d\n",
502 p
->bytesused
, p
->m
.userptr
, p
->length
);
505 printk(KERN_DEBUG
"timecode=%02d:%02d:%02d type=%d, flags=0x%08x, frames=%d, userbits=0x%08x\n",
506 tc
->hours
, tc
->minutes
, tc
->seconds
,
507 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
510 static void v4l_print_exportbuffer(const void *arg
, bool write_only
)
512 const struct v4l2_exportbuffer
*p
= arg
;
514 pr_cont("fd=%d, type=%s, index=%u, plane=%u, flags=0x%08x\n",
515 p
->fd
, prt_names(p
->type
, v4l2_type_names
),
516 p
->index
, p
->plane
, p
->flags
);
519 static void v4l_print_create_buffers(const void *arg
, bool write_only
)
521 const struct v4l2_create_buffers
*p
= arg
;
523 pr_cont("index=%d, count=%d, memory=%s, ",
525 prt_names(p
->memory
, v4l2_memory_names
));
526 v4l_print_format(&p
->format
, write_only
);
529 static void v4l_print_streamparm(const void *arg
, bool write_only
)
531 const struct v4l2_streamparm
*p
= arg
;
533 pr_cont("type=%s", prt_names(p
->type
, v4l2_type_names
));
535 if (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
||
536 p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
537 const struct v4l2_captureparm
*c
= &p
->parm
.capture
;
539 pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, extendedmode=%d, readbuffers=%d\n",
540 c
->capability
, c
->capturemode
,
541 c
->timeperframe
.numerator
, c
->timeperframe
.denominator
,
542 c
->extendedmode
, c
->readbuffers
);
543 } else if (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
||
544 p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
545 const struct v4l2_outputparm
*c
= &p
->parm
.output
;
547 pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, extendedmode=%d, writebuffers=%d\n",
548 c
->capability
, c
->outputmode
,
549 c
->timeperframe
.numerator
, c
->timeperframe
.denominator
,
550 c
->extendedmode
, c
->writebuffers
);
556 static void v4l_print_queryctrl(const void *arg
, bool write_only
)
558 const struct v4l2_queryctrl
*p
= arg
;
560 pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%d/%d, step=%d, default=%d, flags=0x%08x\n",
561 p
->id
, p
->type
, (int)sizeof(p
->name
), p
->name
,
562 p
->minimum
, p
->maximum
,
563 p
->step
, p
->default_value
, p
->flags
);
566 static void v4l_print_query_ext_ctrl(const void *arg
, bool write_only
)
568 const struct v4l2_query_ext_ctrl
*p
= arg
;
570 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",
571 p
->id
, p
->type
, (int)sizeof(p
->name
), p
->name
,
572 p
->minimum
, p
->maximum
,
573 p
->step
, p
->default_value
, p
->flags
,
574 p
->elem_size
, p
->elems
, p
->nr_of_dims
,
575 p
->dims
[0], p
->dims
[1], p
->dims
[2], p
->dims
[3]);
578 static void v4l_print_querymenu(const void *arg
, bool write_only
)
580 const struct v4l2_querymenu
*p
= arg
;
582 pr_cont("id=0x%x, index=%d\n", p
->id
, p
->index
);
585 static void v4l_print_control(const void *arg
, bool write_only
)
587 const struct v4l2_control
*p
= arg
;
589 pr_cont("id=0x%x, value=%d\n", p
->id
, p
->value
);
592 static void v4l_print_ext_controls(const void *arg
, bool write_only
)
594 const struct v4l2_ext_controls
*p
= arg
;
597 pr_cont("which=0x%x, count=%d, error_idx=%d, request_fd=%d",
598 p
->which
, p
->count
, p
->error_idx
, p
->request_fd
);
599 for (i
= 0; i
< p
->count
; i
++) {
600 if (!p
->controls
[i
].size
)
601 pr_cont(", id/val=0x%x/0x%x",
602 p
->controls
[i
].id
, p
->controls
[i
].value
);
604 pr_cont(", id/size=0x%x/%u",
605 p
->controls
[i
].id
, p
->controls
[i
].size
);
610 static void v4l_print_cropcap(const void *arg
, bool write_only
)
612 const struct v4l2_cropcap
*p
= arg
;
614 pr_cont("type=%s, bounds wxh=%dx%d, x,y=%d,%d, defrect wxh=%dx%d, x,y=%d,%d, pixelaspect %d/%d\n",
615 prt_names(p
->type
, v4l2_type_names
),
616 p
->bounds
.width
, p
->bounds
.height
,
617 p
->bounds
.left
, p
->bounds
.top
,
618 p
->defrect
.width
, p
->defrect
.height
,
619 p
->defrect
.left
, p
->defrect
.top
,
620 p
->pixelaspect
.numerator
, p
->pixelaspect
.denominator
);
623 static void v4l_print_crop(const void *arg
, bool write_only
)
625 const struct v4l2_crop
*p
= arg
;
627 pr_cont("type=%s, wxh=%dx%d, x,y=%d,%d\n",
628 prt_names(p
->type
, v4l2_type_names
),
629 p
->c
.width
, p
->c
.height
,
630 p
->c
.left
, p
->c
.top
);
633 static void v4l_print_selection(const void *arg
, bool write_only
)
635 const struct v4l2_selection
*p
= arg
;
637 pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
638 prt_names(p
->type
, v4l2_type_names
),
640 p
->r
.width
, p
->r
.height
, p
->r
.left
, p
->r
.top
);
643 static void v4l_print_jpegcompression(const void *arg
, bool write_only
)
645 const struct v4l2_jpegcompression
*p
= arg
;
647 pr_cont("quality=%d, APPn=%d, APP_len=%d, COM_len=%d, jpeg_markers=0x%x\n",
648 p
->quality
, p
->APPn
, p
->APP_len
,
649 p
->COM_len
, p
->jpeg_markers
);
652 static void v4l_print_enc_idx(const void *arg
, bool write_only
)
654 const struct v4l2_enc_idx
*p
= arg
;
656 pr_cont("entries=%d, entries_cap=%d\n",
657 p
->entries
, p
->entries_cap
);
660 static void v4l_print_encoder_cmd(const void *arg
, bool write_only
)
662 const struct v4l2_encoder_cmd
*p
= arg
;
664 pr_cont("cmd=%d, flags=0x%x\n",
668 static void v4l_print_decoder_cmd(const void *arg
, bool write_only
)
670 const struct v4l2_decoder_cmd
*p
= arg
;
672 pr_cont("cmd=%d, flags=0x%x\n", p
->cmd
, p
->flags
);
674 if (p
->cmd
== V4L2_DEC_CMD_START
)
675 pr_info("speed=%d, format=%u\n",
676 p
->start
.speed
, p
->start
.format
);
677 else if (p
->cmd
== V4L2_DEC_CMD_STOP
)
678 pr_info("pts=%llu\n", p
->stop
.pts
);
681 static void v4l_print_dbg_chip_info(const void *arg
, bool write_only
)
683 const struct v4l2_dbg_chip_info
*p
= arg
;
685 pr_cont("type=%u, ", p
->match
.type
);
686 if (p
->match
.type
== V4L2_CHIP_MATCH_I2C_DRIVER
)
687 pr_cont("name=%.*s, ",
688 (int)sizeof(p
->match
.name
), p
->match
.name
);
690 pr_cont("addr=%u, ", p
->match
.addr
);
691 pr_cont("name=%.*s\n", (int)sizeof(p
->name
), p
->name
);
694 static void v4l_print_dbg_register(const void *arg
, bool write_only
)
696 const struct v4l2_dbg_register
*p
= arg
;
698 pr_cont("type=%u, ", p
->match
.type
);
699 if (p
->match
.type
== V4L2_CHIP_MATCH_I2C_DRIVER
)
700 pr_cont("name=%.*s, ",
701 (int)sizeof(p
->match
.name
), p
->match
.name
);
703 pr_cont("addr=%u, ", p
->match
.addr
);
704 pr_cont("reg=0x%llx, val=0x%llx\n",
708 static void v4l_print_dv_timings(const void *arg
, bool write_only
)
710 const struct v4l2_dv_timings
*p
= arg
;
713 case V4L2_DV_BT_656_1120
:
714 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",
715 p
->bt
.interlaced
, p
->bt
.pixelclock
,
716 p
->bt
.width
, p
->bt
.height
,
717 p
->bt
.polarities
, p
->bt
.hfrontporch
,
718 p
->bt
.hsync
, p
->bt
.hbackporch
,
719 p
->bt
.vfrontporch
, p
->bt
.vsync
,
720 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
721 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
,
722 p
->bt
.standards
, p
->bt
.flags
);
725 pr_cont("type=%d\n", p
->type
);
730 static void v4l_print_enum_dv_timings(const void *arg
, bool write_only
)
732 const struct v4l2_enum_dv_timings
*p
= arg
;
734 pr_cont("index=%u, ", p
->index
);
735 v4l_print_dv_timings(&p
->timings
, write_only
);
738 static void v4l_print_dv_timings_cap(const void *arg
, bool write_only
)
740 const struct v4l2_dv_timings_cap
*p
= arg
;
743 case V4L2_DV_BT_656_1120
:
744 pr_cont("type=bt-656/1120, width=%u-%u, height=%u-%u, pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n",
745 p
->bt
.min_width
, p
->bt
.max_width
,
746 p
->bt
.min_height
, p
->bt
.max_height
,
747 p
->bt
.min_pixelclock
, p
->bt
.max_pixelclock
,
748 p
->bt
.standards
, p
->bt
.capabilities
);
751 pr_cont("type=%u\n", p
->type
);
756 static void v4l_print_frmsizeenum(const void *arg
, bool write_only
)
758 const struct v4l2_frmsizeenum
*p
= arg
;
760 pr_cont("index=%u, pixelformat=%c%c%c%c, type=%u",
762 (p
->pixel_format
& 0xff),
763 (p
->pixel_format
>> 8) & 0xff,
764 (p
->pixel_format
>> 16) & 0xff,
765 (p
->pixel_format
>> 24) & 0xff,
768 case V4L2_FRMSIZE_TYPE_DISCRETE
:
769 pr_cont(", wxh=%ux%u\n",
770 p
->discrete
.width
, p
->discrete
.height
);
772 case V4L2_FRMSIZE_TYPE_STEPWISE
:
773 pr_cont(", min=%ux%u, max=%ux%u, step=%ux%u\n",
774 p
->stepwise
.min_width
,
775 p
->stepwise
.min_height
,
776 p
->stepwise
.max_width
,
777 p
->stepwise
.max_height
,
778 p
->stepwise
.step_width
,
779 p
->stepwise
.step_height
);
781 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
789 static void v4l_print_frmivalenum(const void *arg
, bool write_only
)
791 const struct v4l2_frmivalenum
*p
= arg
;
793 pr_cont("index=%u, pixelformat=%c%c%c%c, wxh=%ux%u, type=%u",
795 (p
->pixel_format
& 0xff),
796 (p
->pixel_format
>> 8) & 0xff,
797 (p
->pixel_format
>> 16) & 0xff,
798 (p
->pixel_format
>> 24) & 0xff,
799 p
->width
, p
->height
, p
->type
);
801 case V4L2_FRMIVAL_TYPE_DISCRETE
:
802 pr_cont(", fps=%d/%d\n",
803 p
->discrete
.numerator
,
804 p
->discrete
.denominator
);
806 case V4L2_FRMIVAL_TYPE_STEPWISE
:
807 pr_cont(", min=%d/%d, max=%d/%d, step=%d/%d\n",
808 p
->stepwise
.min
.numerator
,
809 p
->stepwise
.min
.denominator
,
810 p
->stepwise
.max
.numerator
,
811 p
->stepwise
.max
.denominator
,
812 p
->stepwise
.step
.numerator
,
813 p
->stepwise
.step
.denominator
);
815 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
823 static void v4l_print_event(const void *arg
, bool write_only
)
825 const struct v4l2_event
*p
= arg
;
826 const struct v4l2_event_ctrl
*c
;
828 pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, timestamp=%lu.%9.9lu\n",
829 p
->type
, p
->pending
, p
->sequence
, p
->id
,
830 p
->timestamp
.tv_sec
, p
->timestamp
.tv_nsec
);
832 case V4L2_EVENT_VSYNC
:
833 printk(KERN_DEBUG
"field=%s\n",
834 prt_names(p
->u
.vsync
.field
, v4l2_field_names
));
836 case V4L2_EVENT_CTRL
:
838 printk(KERN_DEBUG
"changes=0x%x, type=%u, ",
839 c
->changes
, c
->type
);
840 if (c
->type
== V4L2_CTRL_TYPE_INTEGER64
)
841 pr_cont("value64=%lld, ", c
->value64
);
843 pr_cont("value=%d, ", c
->value
);
844 pr_cont("flags=0x%x, minimum=%d, maximum=%d, step=%d, default_value=%d\n",
845 c
->flags
, c
->minimum
, c
->maximum
,
846 c
->step
, c
->default_value
);
848 case V4L2_EVENT_FRAME_SYNC
:
849 pr_cont("frame_sequence=%u\n",
850 p
->u
.frame_sync
.frame_sequence
);
855 static void v4l_print_event_subscription(const void *arg
, bool write_only
)
857 const struct v4l2_event_subscription
*p
= arg
;
859 pr_cont("type=0x%x, id=0x%x, flags=0x%x\n",
860 p
->type
, p
->id
, p
->flags
);
863 static void v4l_print_sliced_vbi_cap(const void *arg
, bool write_only
)
865 const struct v4l2_sliced_vbi_cap
*p
= arg
;
868 pr_cont("type=%s, service_set=0x%08x\n",
869 prt_names(p
->type
, v4l2_type_names
), p
->service_set
);
870 for (i
= 0; i
< 24; i
++)
871 printk(KERN_DEBUG
"line[%02u]=0x%04x, 0x%04x\n", i
,
872 p
->service_lines
[0][i
],
873 p
->service_lines
[1][i
]);
876 static void v4l_print_freq_band(const void *arg
, bool write_only
)
878 const struct v4l2_frequency_band
*p
= arg
;
880 pr_cont("tuner=%u, type=%u, index=%u, capability=0x%x, rangelow=%u, rangehigh=%u, modulation=0x%x\n",
881 p
->tuner
, p
->type
, p
->index
,
882 p
->capability
, p
->rangelow
,
883 p
->rangehigh
, p
->modulation
);
886 static void v4l_print_edid(const void *arg
, bool write_only
)
888 const struct v4l2_edid
*p
= arg
;
890 pr_cont("pad=%u, start_block=%u, blocks=%u\n",
891 p
->pad
, p
->start_block
, p
->blocks
);
894 static void v4l_print_u32(const void *arg
, bool write_only
)
896 pr_cont("value=%u\n", *(const u32
*)arg
);
899 static void v4l_print_newline(const void *arg
, bool write_only
)
904 static void v4l_print_default(const void *arg
, bool write_only
)
906 pr_cont("driver-specific ioctl\n");
909 static int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
913 /* zero the reserved fields */
915 for (i
= 0; i
< c
->count
; i
++)
916 c
->controls
[i
].reserved2
[0] = 0;
918 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
919 when using extended controls.
920 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
921 is it allowed for backwards compatibility.
923 if (!allow_priv
&& c
->which
== V4L2_CID_PRIVATE_BASE
)
927 /* Check that all controls are from the same control class. */
928 for (i
= 0; i
< c
->count
; i
++) {
929 if (V4L2_CTRL_ID2WHICH(c
->controls
[i
].id
) != c
->which
) {
937 static int check_fmt(struct file
*file
, enum v4l2_buf_type type
)
939 struct video_device
*vfd
= video_devdata(file
);
940 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
941 bool is_vid
= vfd
->vfl_type
== VFL_TYPE_GRABBER
;
942 bool is_vbi
= vfd
->vfl_type
== VFL_TYPE_VBI
;
943 bool is_sdr
= vfd
->vfl_type
== VFL_TYPE_SDR
;
944 bool is_tch
= vfd
->vfl_type
== VFL_TYPE_TOUCH
;
945 bool is_rx
= vfd
->vfl_dir
!= VFL_DIR_TX
;
946 bool is_tx
= vfd
->vfl_dir
!= VFL_DIR_RX
;
952 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
953 if ((is_vid
|| is_tch
) && is_rx
&&
954 (ops
->vidioc_g_fmt_vid_cap
|| ops
->vidioc_g_fmt_vid_cap_mplane
))
957 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
958 if (is_vid
&& is_rx
&& ops
->vidioc_g_fmt_vid_cap_mplane
)
961 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
962 if (is_vid
&& is_rx
&& ops
->vidioc_g_fmt_vid_overlay
)
965 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
966 if (is_vid
&& is_tx
&&
967 (ops
->vidioc_g_fmt_vid_out
|| ops
->vidioc_g_fmt_vid_out_mplane
))
970 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
971 if (is_vid
&& is_tx
&& ops
->vidioc_g_fmt_vid_out_mplane
)
974 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
975 if (is_vid
&& is_tx
&& ops
->vidioc_g_fmt_vid_out_overlay
)
978 case V4L2_BUF_TYPE_VBI_CAPTURE
:
979 if (is_vbi
&& is_rx
&& ops
->vidioc_g_fmt_vbi_cap
)
982 case V4L2_BUF_TYPE_VBI_OUTPUT
:
983 if (is_vbi
&& is_tx
&& ops
->vidioc_g_fmt_vbi_out
)
986 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
987 if (is_vbi
&& is_rx
&& ops
->vidioc_g_fmt_sliced_vbi_cap
)
990 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
991 if (is_vbi
&& is_tx
&& ops
->vidioc_g_fmt_sliced_vbi_out
)
994 case V4L2_BUF_TYPE_SDR_CAPTURE
:
995 if (is_sdr
&& is_rx
&& ops
->vidioc_g_fmt_sdr_cap
)
998 case V4L2_BUF_TYPE_SDR_OUTPUT
:
999 if (is_sdr
&& is_tx
&& ops
->vidioc_g_fmt_sdr_out
)
1002 case V4L2_BUF_TYPE_META_CAPTURE
:
1003 if (is_vid
&& is_rx
&& ops
->vidioc_g_fmt_meta_cap
)
1006 case V4L2_BUF_TYPE_META_OUTPUT
:
1007 if (is_vid
&& is_tx
&& ops
->vidioc_g_fmt_meta_out
)
1016 static void v4l_sanitize_format(struct v4l2_format
*fmt
)
1018 unsigned int offset
;
1021 * The v4l2_pix_format structure has been extended with fields that were
1022 * not previously required to be set to zero by applications. The priv
1023 * field, when set to a magic value, indicates the the extended fields
1024 * are valid. Otherwise they will contain undefined values. To simplify
1025 * the API towards drivers zero the extended fields and set the priv
1026 * field to the magic value when the extended pixel format structure
1027 * isn't used by applications.
1030 if (fmt
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
1031 fmt
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1034 if (fmt
->fmt
.pix
.priv
== V4L2_PIX_FMT_PRIV_MAGIC
)
1037 fmt
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1039 offset
= offsetof(struct v4l2_pix_format
, priv
)
1040 + sizeof(fmt
->fmt
.pix
.priv
);
1041 memset(((void *)&fmt
->fmt
.pix
) + offset
, 0,
1042 sizeof(fmt
->fmt
.pix
) - offset
);
1045 static int v4l_querycap(const struct v4l2_ioctl_ops
*ops
,
1046 struct file
*file
, void *fh
, void *arg
)
1048 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
1049 struct video_device
*vfd
= video_devdata(file
);
1052 cap
->version
= LINUX_VERSION_CODE
;
1053 cap
->device_caps
= vfd
->device_caps
;
1054 cap
->capabilities
= vfd
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
1056 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
1058 cap
->capabilities
|= V4L2_CAP_EXT_PIX_FORMAT
;
1060 * Drivers MUST fill in device_caps, so check for this and
1061 * warn if it was forgotten.
1063 WARN(!(cap
->capabilities
& V4L2_CAP_DEVICE_CAPS
) ||
1064 !cap
->device_caps
, "Bad caps for driver %s, %x %x",
1065 cap
->driver
, cap
->capabilities
, cap
->device_caps
);
1066 cap
->device_caps
|= V4L2_CAP_EXT_PIX_FORMAT
;
1071 static int v4l_s_input(const struct v4l2_ioctl_ops
*ops
,
1072 struct file
*file
, void *fh
, void *arg
)
1074 struct video_device
*vfd
= video_devdata(file
);
1077 ret
= v4l_enable_media_source(vfd
);
1080 return ops
->vidioc_s_input(file
, fh
, *(unsigned int *)arg
);
1083 static int v4l_s_output(const struct v4l2_ioctl_ops
*ops
,
1084 struct file
*file
, void *fh
, void *arg
)
1086 return ops
->vidioc_s_output(file
, fh
, *(unsigned int *)arg
);
1089 static int v4l_g_priority(const struct v4l2_ioctl_ops
*ops
,
1090 struct file
*file
, void *fh
, void *arg
)
1092 struct video_device
*vfd
;
1095 vfd
= video_devdata(file
);
1096 *p
= v4l2_prio_max(vfd
->prio
);
1100 static int v4l_s_priority(const struct v4l2_ioctl_ops
*ops
,
1101 struct file
*file
, void *fh
, void *arg
)
1103 struct video_device
*vfd
;
1104 struct v4l2_fh
*vfh
;
1107 vfd
= video_devdata(file
);
1108 if (!test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
))
1110 vfh
= file
->private_data
;
1111 return v4l2_prio_change(vfd
->prio
, &vfh
->prio
, *p
);
1114 static int v4l_enuminput(const struct v4l2_ioctl_ops
*ops
,
1115 struct file
*file
, void *fh
, void *arg
)
1117 struct video_device
*vfd
= video_devdata(file
);
1118 struct v4l2_input
*p
= arg
;
1121 * We set the flags for CAP_DV_TIMINGS &
1122 * CAP_STD here based on ioctl handler provided by the
1123 * driver. If the driver doesn't support these
1124 * for a specific input, it must override these flags.
1126 if (is_valid_ioctl(vfd
, VIDIOC_S_STD
))
1127 p
->capabilities
|= V4L2_IN_CAP_STD
;
1129 return ops
->vidioc_enum_input(file
, fh
, p
);
1132 static int v4l_enumoutput(const struct v4l2_ioctl_ops
*ops
,
1133 struct file
*file
, void *fh
, void *arg
)
1135 struct video_device
*vfd
= video_devdata(file
);
1136 struct v4l2_output
*p
= arg
;
1139 * We set the flags for CAP_DV_TIMINGS &
1140 * CAP_STD here based on ioctl handler provided by the
1141 * driver. If the driver doesn't support these
1142 * for a specific output, it must override these flags.
1144 if (is_valid_ioctl(vfd
, VIDIOC_S_STD
))
1145 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1147 return ops
->vidioc_enum_output(file
, fh
, p
);
1150 static void v4l_fill_fmtdesc(struct v4l2_fmtdesc
*fmt
)
1152 const unsigned sz
= sizeof(fmt
->description
);
1153 const char *descr
= NULL
;
1157 * We depart from the normal coding style here since the descriptions
1158 * should be aligned so it is easy to see which descriptions will be
1159 * longer than 31 characters (the max length for a description).
1160 * And frankly, this is easier to read anyway.
1162 * Note that gcc will use O(log N) comparisons to find the right case.
1164 switch (fmt
->pixelformat
) {
1165 /* Max description length mask: descr = "0123456789012345678901234567890" */
1166 case V4L2_PIX_FMT_RGB332
: descr
= "8-bit RGB 3-3-2"; break;
1167 case V4L2_PIX_FMT_RGB444
: descr
= "16-bit A/XRGB 4-4-4-4"; break;
1168 case V4L2_PIX_FMT_ARGB444
: descr
= "16-bit ARGB 4-4-4-4"; break;
1169 case V4L2_PIX_FMT_XRGB444
: descr
= "16-bit XRGB 4-4-4-4"; break;
1170 case V4L2_PIX_FMT_RGB555
: descr
= "16-bit A/XRGB 1-5-5-5"; break;
1171 case V4L2_PIX_FMT_ARGB555
: descr
= "16-bit ARGB 1-5-5-5"; break;
1172 case V4L2_PIX_FMT_XRGB555
: descr
= "16-bit XRGB 1-5-5-5"; break;
1173 case V4L2_PIX_FMT_RGB565
: descr
= "16-bit RGB 5-6-5"; break;
1174 case V4L2_PIX_FMT_RGB555X
: descr
= "16-bit A/XRGB 1-5-5-5 BE"; break;
1175 case V4L2_PIX_FMT_ARGB555X
: descr
= "16-bit ARGB 1-5-5-5 BE"; break;
1176 case V4L2_PIX_FMT_XRGB555X
: descr
= "16-bit XRGB 1-5-5-5 BE"; break;
1177 case V4L2_PIX_FMT_RGB565X
: descr
= "16-bit RGB 5-6-5 BE"; break;
1178 case V4L2_PIX_FMT_BGR666
: descr
= "18-bit BGRX 6-6-6-14"; break;
1179 case V4L2_PIX_FMT_BGR24
: descr
= "24-bit BGR 8-8-8"; break;
1180 case V4L2_PIX_FMT_RGB24
: descr
= "24-bit RGB 8-8-8"; break;
1181 case V4L2_PIX_FMT_BGR32
: descr
= "32-bit BGRA/X 8-8-8-8"; break;
1182 case V4L2_PIX_FMT_ABGR32
: descr
= "32-bit BGRA 8-8-8-8"; break;
1183 case V4L2_PIX_FMT_XBGR32
: descr
= "32-bit BGRX 8-8-8-8"; break;
1184 case V4L2_PIX_FMT_RGB32
: descr
= "32-bit A/XRGB 8-8-8-8"; break;
1185 case V4L2_PIX_FMT_ARGB32
: descr
= "32-bit ARGB 8-8-8-8"; break;
1186 case V4L2_PIX_FMT_XRGB32
: descr
= "32-bit XRGB 8-8-8-8"; break;
1187 case V4L2_PIX_FMT_GREY
: descr
= "8-bit Greyscale"; break;
1188 case V4L2_PIX_FMT_Y4
: descr
= "4-bit Greyscale"; break;
1189 case V4L2_PIX_FMT_Y6
: descr
= "6-bit Greyscale"; break;
1190 case V4L2_PIX_FMT_Y10
: descr
= "10-bit Greyscale"; break;
1191 case V4L2_PIX_FMT_Y12
: descr
= "12-bit Greyscale"; break;
1192 case V4L2_PIX_FMT_Y16
: descr
= "16-bit Greyscale"; break;
1193 case V4L2_PIX_FMT_Y16_BE
: descr
= "16-bit Greyscale BE"; break;
1194 case V4L2_PIX_FMT_Y10BPACK
: descr
= "10-bit Greyscale (Packed)"; break;
1195 case V4L2_PIX_FMT_Y10P
: descr
= "10-bit Greyscale (MIPI Packed)"; break;
1196 case V4L2_PIX_FMT_Y8I
: descr
= "Interleaved 8-bit Greyscale"; break;
1197 case V4L2_PIX_FMT_Y12I
: descr
= "Interleaved 12-bit Greyscale"; break;
1198 case V4L2_PIX_FMT_Z16
: descr
= "16-bit Depth"; break;
1199 case V4L2_PIX_FMT_INZI
: descr
= "Planar 10:16 Greyscale Depth"; break;
1200 case V4L2_PIX_FMT_CNF4
: descr
= "4-bit Depth Confidence (Packed)"; break;
1201 case V4L2_PIX_FMT_PAL8
: descr
= "8-bit Palette"; break;
1202 case V4L2_PIX_FMT_UV8
: descr
= "8-bit Chrominance UV 4-4"; break;
1203 case V4L2_PIX_FMT_YVU410
: descr
= "Planar YVU 4:1:0"; break;
1204 case V4L2_PIX_FMT_YVU420
: descr
= "Planar YVU 4:2:0"; break;
1205 case V4L2_PIX_FMT_YUYV
: descr
= "YUYV 4:2:2"; break;
1206 case V4L2_PIX_FMT_YYUV
: descr
= "YYUV 4:2:2"; break;
1207 case V4L2_PIX_FMT_YVYU
: descr
= "YVYU 4:2:2"; break;
1208 case V4L2_PIX_FMT_UYVY
: descr
= "UYVY 4:2:2"; break;
1209 case V4L2_PIX_FMT_VYUY
: descr
= "VYUY 4:2:2"; break;
1210 case V4L2_PIX_FMT_YUV422P
: descr
= "Planar YUV 4:2:2"; break;
1211 case V4L2_PIX_FMT_YUV411P
: descr
= "Planar YUV 4:1:1"; break;
1212 case V4L2_PIX_FMT_Y41P
: descr
= "YUV 4:1:1 (Packed)"; break;
1213 case V4L2_PIX_FMT_YUV444
: descr
= "16-bit A/XYUV 4-4-4-4"; break;
1214 case V4L2_PIX_FMT_YUV555
: descr
= "16-bit A/XYUV 1-5-5-5"; break;
1215 case V4L2_PIX_FMT_YUV565
: descr
= "16-bit YUV 5-6-5"; break;
1216 case V4L2_PIX_FMT_YUV32
: descr
= "32-bit A/XYUV 8-8-8-8"; break;
1217 case V4L2_PIX_FMT_YUV410
: descr
= "Planar YUV 4:1:0"; break;
1218 case V4L2_PIX_FMT_YUV420
: descr
= "Planar YUV 4:2:0"; break;
1219 case V4L2_PIX_FMT_HI240
: descr
= "8-bit Dithered RGB (BTTV)"; break;
1220 case V4L2_PIX_FMT_HM12
: descr
= "YUV 4:2:0 (16x16 Macroblocks)"; break;
1221 case V4L2_PIX_FMT_M420
: descr
= "YUV 4:2:0 (M420)"; break;
1222 case V4L2_PIX_FMT_NV12
: descr
= "Y/CbCr 4:2:0"; break;
1223 case V4L2_PIX_FMT_NV21
: descr
= "Y/CrCb 4:2:0"; break;
1224 case V4L2_PIX_FMT_NV16
: descr
= "Y/CbCr 4:2:2"; break;
1225 case V4L2_PIX_FMT_NV61
: descr
= "Y/CrCb 4:2:2"; break;
1226 case V4L2_PIX_FMT_NV24
: descr
= "Y/CbCr 4:4:4"; break;
1227 case V4L2_PIX_FMT_NV42
: descr
= "Y/CrCb 4:4:4"; break;
1228 case V4L2_PIX_FMT_NV12M
: descr
= "Y/CbCr 4:2:0 (N-C)"; break;
1229 case V4L2_PIX_FMT_NV21M
: descr
= "Y/CrCb 4:2:0 (N-C)"; break;
1230 case V4L2_PIX_FMT_NV16M
: descr
= "Y/CbCr 4:2:2 (N-C)"; break;
1231 case V4L2_PIX_FMT_NV61M
: descr
= "Y/CrCb 4:2:2 (N-C)"; break;
1232 case V4L2_PIX_FMT_NV12MT
: descr
= "Y/CbCr 4:2:0 (64x32 MB, N-C)"; break;
1233 case V4L2_PIX_FMT_NV12MT_16X16
: descr
= "Y/CbCr 4:2:0 (16x16 MB, N-C)"; break;
1234 case V4L2_PIX_FMT_YUV420M
: descr
= "Planar YUV 4:2:0 (N-C)"; break;
1235 case V4L2_PIX_FMT_YVU420M
: descr
= "Planar YVU 4:2:0 (N-C)"; break;
1236 case V4L2_PIX_FMT_YUV422M
: descr
= "Planar YUV 4:2:2 (N-C)"; break;
1237 case V4L2_PIX_FMT_YVU422M
: descr
= "Planar YVU 4:2:2 (N-C)"; break;
1238 case V4L2_PIX_FMT_YUV444M
: descr
= "Planar YUV 4:4:4 (N-C)"; break;
1239 case V4L2_PIX_FMT_YVU444M
: descr
= "Planar YVU 4:4:4 (N-C)"; break;
1240 case V4L2_PIX_FMT_SBGGR8
: descr
= "8-bit Bayer BGBG/GRGR"; break;
1241 case V4L2_PIX_FMT_SGBRG8
: descr
= "8-bit Bayer GBGB/RGRG"; break;
1242 case V4L2_PIX_FMT_SGRBG8
: descr
= "8-bit Bayer GRGR/BGBG"; break;
1243 case V4L2_PIX_FMT_SRGGB8
: descr
= "8-bit Bayer RGRG/GBGB"; break;
1244 case V4L2_PIX_FMT_SBGGR10
: descr
= "10-bit Bayer BGBG/GRGR"; break;
1245 case V4L2_PIX_FMT_SGBRG10
: descr
= "10-bit Bayer GBGB/RGRG"; break;
1246 case V4L2_PIX_FMT_SGRBG10
: descr
= "10-bit Bayer GRGR/BGBG"; break;
1247 case V4L2_PIX_FMT_SRGGB10
: descr
= "10-bit Bayer RGRG/GBGB"; break;
1248 case V4L2_PIX_FMT_SBGGR10P
: descr
= "10-bit Bayer BGBG/GRGR Packed"; break;
1249 case V4L2_PIX_FMT_SGBRG10P
: descr
= "10-bit Bayer GBGB/RGRG Packed"; break;
1250 case V4L2_PIX_FMT_SGRBG10P
: descr
= "10-bit Bayer GRGR/BGBG Packed"; break;
1251 case V4L2_PIX_FMT_SRGGB10P
: descr
= "10-bit Bayer RGRG/GBGB Packed"; break;
1252 case V4L2_PIX_FMT_IPU3_SBGGR10
: descr
= "10-bit bayer BGGR IPU3 Packed"; break;
1253 case V4L2_PIX_FMT_IPU3_SGBRG10
: descr
= "10-bit bayer GBRG IPU3 Packed"; break;
1254 case V4L2_PIX_FMT_IPU3_SGRBG10
: descr
= "10-bit bayer GRBG IPU3 Packed"; break;
1255 case V4L2_PIX_FMT_IPU3_SRGGB10
: descr
= "10-bit bayer RGGB IPU3 Packed"; break;
1256 case V4L2_PIX_FMT_SBGGR10ALAW8
: descr
= "8-bit Bayer BGBG/GRGR (A-law)"; break;
1257 case V4L2_PIX_FMT_SGBRG10ALAW8
: descr
= "8-bit Bayer GBGB/RGRG (A-law)"; break;
1258 case V4L2_PIX_FMT_SGRBG10ALAW8
: descr
= "8-bit Bayer GRGR/BGBG (A-law)"; break;
1259 case V4L2_PIX_FMT_SRGGB10ALAW8
: descr
= "8-bit Bayer RGRG/GBGB (A-law)"; break;
1260 case V4L2_PIX_FMT_SBGGR10DPCM8
: descr
= "8-bit Bayer BGBG/GRGR (DPCM)"; break;
1261 case V4L2_PIX_FMT_SGBRG10DPCM8
: descr
= "8-bit Bayer GBGB/RGRG (DPCM)"; break;
1262 case V4L2_PIX_FMT_SGRBG10DPCM8
: descr
= "8-bit Bayer GRGR/BGBG (DPCM)"; break;
1263 case V4L2_PIX_FMT_SRGGB10DPCM8
: descr
= "8-bit Bayer RGRG/GBGB (DPCM)"; break;
1264 case V4L2_PIX_FMT_SBGGR12
: descr
= "12-bit Bayer BGBG/GRGR"; break;
1265 case V4L2_PIX_FMT_SGBRG12
: descr
= "12-bit Bayer GBGB/RGRG"; break;
1266 case V4L2_PIX_FMT_SGRBG12
: descr
= "12-bit Bayer GRGR/BGBG"; break;
1267 case V4L2_PIX_FMT_SRGGB12
: descr
= "12-bit Bayer RGRG/GBGB"; break;
1268 case V4L2_PIX_FMT_SBGGR12P
: descr
= "12-bit Bayer BGBG/GRGR Packed"; break;
1269 case V4L2_PIX_FMT_SGBRG12P
: descr
= "12-bit Bayer GBGB/RGRG Packed"; break;
1270 case V4L2_PIX_FMT_SGRBG12P
: descr
= "12-bit Bayer GRGR/BGBG Packed"; break;
1271 case V4L2_PIX_FMT_SRGGB12P
: descr
= "12-bit Bayer RGRG/GBGB Packed"; break;
1272 case V4L2_PIX_FMT_SBGGR14P
: descr
= "14-bit Bayer BGBG/GRGR Packed"; break;
1273 case V4L2_PIX_FMT_SGBRG14P
: descr
= "14-bit Bayer GBGB/RGRG Packed"; break;
1274 case V4L2_PIX_FMT_SGRBG14P
: descr
= "14-bit Bayer GRGR/BGBG Packed"; break;
1275 case V4L2_PIX_FMT_SRGGB14P
: descr
= "14-bit Bayer RGRG/GBGB Packed"; break;
1276 case V4L2_PIX_FMT_SBGGR16
: descr
= "16-bit Bayer BGBG/GRGR"; break;
1277 case V4L2_PIX_FMT_SGBRG16
: descr
= "16-bit Bayer GBGB/RGRG"; break;
1278 case V4L2_PIX_FMT_SGRBG16
: descr
= "16-bit Bayer GRGR/BGBG"; break;
1279 case V4L2_PIX_FMT_SRGGB16
: descr
= "16-bit Bayer RGRG/GBGB"; break;
1280 case V4L2_PIX_FMT_SN9C20X_I420
: descr
= "GSPCA SN9C20X I420"; break;
1281 case V4L2_PIX_FMT_SPCA501
: descr
= "GSPCA SPCA501"; break;
1282 case V4L2_PIX_FMT_SPCA505
: descr
= "GSPCA SPCA505"; break;
1283 case V4L2_PIX_FMT_SPCA508
: descr
= "GSPCA SPCA508"; break;
1284 case V4L2_PIX_FMT_STV0680
: descr
= "GSPCA STV0680"; break;
1285 case V4L2_PIX_FMT_TM6000
: descr
= "A/V + VBI Mux Packet"; break;
1286 case V4L2_PIX_FMT_CIT_YYVYUY
: descr
= "GSPCA CIT YYVYUY"; break;
1287 case V4L2_PIX_FMT_KONICA420
: descr
= "GSPCA KONICA420"; break;
1288 case V4L2_PIX_FMT_HSV24
: descr
= "24-bit HSV 8-8-8"; break;
1289 case V4L2_PIX_FMT_HSV32
: descr
= "32-bit XHSV 8-8-8-8"; break;
1290 case V4L2_SDR_FMT_CU8
: descr
= "Complex U8"; break;
1291 case V4L2_SDR_FMT_CU16LE
: descr
= "Complex U16LE"; break;
1292 case V4L2_SDR_FMT_CS8
: descr
= "Complex S8"; break;
1293 case V4L2_SDR_FMT_CS14LE
: descr
= "Complex S14LE"; break;
1294 case V4L2_SDR_FMT_RU12LE
: descr
= "Real U12LE"; break;
1295 case V4L2_SDR_FMT_PCU16BE
: descr
= "Planar Complex U16BE"; break;
1296 case V4L2_SDR_FMT_PCU18BE
: descr
= "Planar Complex U18BE"; break;
1297 case V4L2_SDR_FMT_PCU20BE
: descr
= "Planar Complex U20BE"; break;
1298 case V4L2_TCH_FMT_DELTA_TD16
: descr
= "16-bit signed deltas"; break;
1299 case V4L2_TCH_FMT_DELTA_TD08
: descr
= "8-bit signed deltas"; break;
1300 case V4L2_TCH_FMT_TU16
: descr
= "16-bit unsigned touch data"; break;
1301 case V4L2_TCH_FMT_TU08
: descr
= "8-bit unsigned touch data"; break;
1302 case V4L2_META_FMT_VSP1_HGO
: descr
= "R-Car VSP1 1-D Histogram"; break;
1303 case V4L2_META_FMT_VSP1_HGT
: descr
= "R-Car VSP1 2-D Histogram"; break;
1304 case V4L2_META_FMT_UVC
: descr
= "UVC payload header metadata"; break;
1307 /* Compressed formats */
1308 flags
= V4L2_FMT_FLAG_COMPRESSED
;
1309 switch (fmt
->pixelformat
) {
1310 /* Max description length mask: descr = "0123456789012345678901234567890" */
1311 case V4L2_PIX_FMT_MJPEG
: descr
= "Motion-JPEG"; break;
1312 case V4L2_PIX_FMT_JPEG
: descr
= "JFIF JPEG"; break;
1313 case V4L2_PIX_FMT_DV
: descr
= "1394"; break;
1314 case V4L2_PIX_FMT_MPEG
: descr
= "MPEG-1/2/4"; break;
1315 case V4L2_PIX_FMT_H264
: descr
= "H.264"; break;
1316 case V4L2_PIX_FMT_H264_NO_SC
: descr
= "H.264 (No Start Codes)"; break;
1317 case V4L2_PIX_FMT_H264_MVC
: descr
= "H.264 MVC"; break;
1318 case V4L2_PIX_FMT_H263
: descr
= "H.263"; break;
1319 case V4L2_PIX_FMT_MPEG1
: descr
= "MPEG-1 ES"; break;
1320 case V4L2_PIX_FMT_MPEG2
: descr
= "MPEG-2 ES"; break;
1321 case V4L2_PIX_FMT_MPEG2_SLICE
: descr
= "MPEG-2 Parsed Slice Data"; break;
1322 case V4L2_PIX_FMT_MPEG4
: descr
= "MPEG-4 part 2 ES"; break;
1323 case V4L2_PIX_FMT_XVID
: descr
= "Xvid"; break;
1324 case V4L2_PIX_FMT_VC1_ANNEX_G
: descr
= "VC-1 (SMPTE 412M Annex G)"; break;
1325 case V4L2_PIX_FMT_VC1_ANNEX_L
: descr
= "VC-1 (SMPTE 412M Annex L)"; break;
1326 case V4L2_PIX_FMT_VP8
: descr
= "VP8"; break;
1327 case V4L2_PIX_FMT_VP9
: descr
= "VP9"; break;
1328 case V4L2_PIX_FMT_HEVC
: descr
= "HEVC"; break; /* aka H.265 */
1329 case V4L2_PIX_FMT_FWHT
: descr
= "FWHT"; break; /* used in vicodec */
1330 case V4L2_PIX_FMT_CPIA1
: descr
= "GSPCA CPiA YUV"; break;
1331 case V4L2_PIX_FMT_WNVA
: descr
= "WNVA"; break;
1332 case V4L2_PIX_FMT_SN9C10X
: descr
= "GSPCA SN9C10X"; break;
1333 case V4L2_PIX_FMT_PWC1
: descr
= "Raw Philips Webcam Type (Old)"; break;
1334 case V4L2_PIX_FMT_PWC2
: descr
= "Raw Philips Webcam Type (New)"; break;
1335 case V4L2_PIX_FMT_ET61X251
: descr
= "GSPCA ET61X251"; break;
1336 case V4L2_PIX_FMT_SPCA561
: descr
= "GSPCA SPCA561"; break;
1337 case V4L2_PIX_FMT_PAC207
: descr
= "GSPCA PAC207"; break;
1338 case V4L2_PIX_FMT_MR97310A
: descr
= "GSPCA MR97310A"; break;
1339 case V4L2_PIX_FMT_JL2005BCD
: descr
= "GSPCA JL2005BCD"; break;
1340 case V4L2_PIX_FMT_SN9C2028
: descr
= "GSPCA SN9C2028"; break;
1341 case V4L2_PIX_FMT_SQ905C
: descr
= "GSPCA SQ905C"; break;
1342 case V4L2_PIX_FMT_PJPG
: descr
= "GSPCA PJPG"; break;
1343 case V4L2_PIX_FMT_OV511
: descr
= "GSPCA OV511"; break;
1344 case V4L2_PIX_FMT_OV518
: descr
= "GSPCA OV518"; break;
1345 case V4L2_PIX_FMT_JPGL
: descr
= "JPEG Lite"; break;
1346 case V4L2_PIX_FMT_SE401
: descr
= "GSPCA SE401"; break;
1347 case V4L2_PIX_FMT_S5C_UYVY_JPG
: descr
= "S5C73MX interleaved UYVY/JPEG"; break;
1348 case V4L2_PIX_FMT_MT21C
: descr
= "Mediatek Compressed Format"; break;
1349 case V4L2_PIX_FMT_SUNXI_TILED_NV12
: descr
= "Sunxi Tiled NV12 Format"; break;
1351 if (fmt
->description
[0])
1353 WARN(1, "Unknown pixelformat 0x%08x\n", fmt
->pixelformat
);
1355 snprintf(fmt
->description
, sz
, "%c%c%c%c%s",
1356 (char)(fmt
->pixelformat
& 0x7f),
1357 (char)((fmt
->pixelformat
>> 8) & 0x7f),
1358 (char)((fmt
->pixelformat
>> 16) & 0x7f),
1359 (char)((fmt
->pixelformat
>> 24) & 0x7f),
1360 (fmt
->pixelformat
& (1 << 31)) ? "-BE" : "");
1366 WARN_ON(strscpy(fmt
->description
, descr
, sz
) >= sz
);
1370 static int v4l_enum_fmt(const struct v4l2_ioctl_ops
*ops
,
1371 struct file
*file
, void *fh
, void *arg
)
1373 struct v4l2_fmtdesc
*p
= arg
;
1374 int ret
= check_fmt(file
, p
->type
);
1381 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1382 if (unlikely(!ops
->vidioc_enum_fmt_vid_cap
))
1384 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, arg
);
1386 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1387 if (unlikely(!ops
->vidioc_enum_fmt_vid_cap_mplane
))
1389 ret
= ops
->vidioc_enum_fmt_vid_cap_mplane(file
, fh
, arg
);
1391 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1392 if (unlikely(!ops
->vidioc_enum_fmt_vid_overlay
))
1394 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
, fh
, arg
);
1396 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1397 if (unlikely(!ops
->vidioc_enum_fmt_vid_out
))
1399 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, arg
);
1401 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1402 if (unlikely(!ops
->vidioc_enum_fmt_vid_out_mplane
))
1404 ret
= ops
->vidioc_enum_fmt_vid_out_mplane(file
, fh
, arg
);
1406 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1407 if (unlikely(!ops
->vidioc_enum_fmt_sdr_cap
))
1409 ret
= ops
->vidioc_enum_fmt_sdr_cap(file
, fh
, arg
);
1411 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1412 if (unlikely(!ops
->vidioc_enum_fmt_sdr_out
))
1414 ret
= ops
->vidioc_enum_fmt_sdr_out(file
, fh
, arg
);
1416 case V4L2_BUF_TYPE_META_CAPTURE
:
1417 if (unlikely(!ops
->vidioc_enum_fmt_meta_cap
))
1419 ret
= ops
->vidioc_enum_fmt_meta_cap(file
, fh
, arg
);
1421 case V4L2_BUF_TYPE_META_OUTPUT
:
1422 if (unlikely(!ops
->vidioc_enum_fmt_meta_out
))
1424 ret
= ops
->vidioc_enum_fmt_meta_out(file
, fh
, arg
);
1428 v4l_fill_fmtdesc(p
);
1432 static int v4l_g_fmt(const struct v4l2_ioctl_ops
*ops
,
1433 struct file
*file
, void *fh
, void *arg
)
1435 struct v4l2_format
*p
= arg
;
1436 int ret
= check_fmt(file
, p
->type
);
1442 * fmt can't be cleared for these overlay types due to the 'clips'
1443 * 'clipcount' and 'bitmap' pointers in struct v4l2_window.
1444 * Those are provided by the user. So handle these two overlay types
1445 * first, and then just do a simple memset for the other types.
1448 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1449 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
: {
1450 struct v4l2_clip __user
*clips
= p
->fmt
.win
.clips
;
1451 u32 clipcount
= p
->fmt
.win
.clipcount
;
1452 void __user
*bitmap
= p
->fmt
.win
.bitmap
;
1454 memset(&p
->fmt
, 0, sizeof(p
->fmt
));
1455 p
->fmt
.win
.clips
= clips
;
1456 p
->fmt
.win
.clipcount
= clipcount
;
1457 p
->fmt
.win
.bitmap
= bitmap
;
1461 memset(&p
->fmt
, 0, sizeof(p
->fmt
));
1466 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1467 if (unlikely(!ops
->vidioc_g_fmt_vid_cap
))
1469 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1470 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, arg
);
1471 /* just in case the driver zeroed it again */
1472 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1474 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1475 return ops
->vidioc_g_fmt_vid_cap_mplane(file
, fh
, arg
);
1476 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1477 return ops
->vidioc_g_fmt_vid_overlay(file
, fh
, arg
);
1478 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1479 return ops
->vidioc_g_fmt_vbi_cap(file
, fh
, arg
);
1480 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
1481 return ops
->vidioc_g_fmt_sliced_vbi_cap(file
, fh
, arg
);
1482 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1483 if (unlikely(!ops
->vidioc_g_fmt_vid_out
))
1485 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1486 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, arg
);
1487 /* just in case the driver zeroed it again */
1488 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1490 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1491 return ops
->vidioc_g_fmt_vid_out_mplane(file
, fh
, arg
);
1492 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
1493 return ops
->vidioc_g_fmt_vid_out_overlay(file
, fh
, arg
);
1494 case V4L2_BUF_TYPE_VBI_OUTPUT
:
1495 return ops
->vidioc_g_fmt_vbi_out(file
, fh
, arg
);
1496 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1497 return ops
->vidioc_g_fmt_sliced_vbi_out(file
, fh
, arg
);
1498 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1499 return ops
->vidioc_g_fmt_sdr_cap(file
, fh
, arg
);
1500 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1501 return ops
->vidioc_g_fmt_sdr_out(file
, fh
, arg
);
1502 case V4L2_BUF_TYPE_META_CAPTURE
:
1503 return ops
->vidioc_g_fmt_meta_cap(file
, fh
, arg
);
1504 case V4L2_BUF_TYPE_META_OUTPUT
:
1505 return ops
->vidioc_g_fmt_meta_out(file
, fh
, arg
);
1510 static void v4l_pix_format_touch(struct v4l2_pix_format
*p
)
1513 * The v4l2_pix_format structure contains fields that make no sense for
1514 * touch. Set them to default values in this case.
1517 p
->field
= V4L2_FIELD_NONE
;
1518 p
->colorspace
= V4L2_COLORSPACE_RAW
;
1521 p
->quantization
= 0;
1525 static int v4l_s_fmt(const struct v4l2_ioctl_ops
*ops
,
1526 struct file
*file
, void *fh
, void *arg
)
1528 struct v4l2_format
*p
= arg
;
1529 struct video_device
*vfd
= video_devdata(file
);
1530 int ret
= check_fmt(file
, p
->type
);
1536 ret
= v4l_enable_media_source(vfd
);
1539 v4l_sanitize_format(p
);
1542 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1543 if (unlikely(!ops
->vidioc_s_fmt_vid_cap
))
1545 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1546 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, arg
);
1547 /* just in case the driver zeroed it again */
1548 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1549 if (vfd
->vfl_type
== VFL_TYPE_TOUCH
)
1550 v4l_pix_format_touch(&p
->fmt
.pix
);
1552 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1553 if (unlikely(!ops
->vidioc_s_fmt_vid_cap_mplane
))
1555 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1556 if (p
->fmt
.pix_mp
.num_planes
> VIDEO_MAX_PLANES
)
1558 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1559 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1561 return ops
->vidioc_s_fmt_vid_cap_mplane(file
, fh
, arg
);
1562 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1563 if (unlikely(!ops
->vidioc_s_fmt_vid_overlay
))
1565 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1566 return ops
->vidioc_s_fmt_vid_overlay(file
, fh
, arg
);
1567 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1568 if (unlikely(!ops
->vidioc_s_fmt_vbi_cap
))
1570 CLEAR_AFTER_FIELD(p
, fmt
.vbi
);
1571 return ops
->vidioc_s_fmt_vbi_cap(file
, fh
, arg
);
1572 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
1573 if (unlikely(!ops
->vidioc_s_fmt_sliced_vbi_cap
))
1575 CLEAR_AFTER_FIELD(p
, fmt
.sliced
);
1576 return ops
->vidioc_s_fmt_sliced_vbi_cap(file
, fh
, arg
);
1577 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1578 if (unlikely(!ops
->vidioc_s_fmt_vid_out
))
1580 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1581 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, arg
);
1582 /* just in case the driver zeroed it again */
1583 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1585 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1586 if (unlikely(!ops
->vidioc_s_fmt_vid_out_mplane
))
1588 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1589 if (p
->fmt
.pix_mp
.num_planes
> VIDEO_MAX_PLANES
)
1591 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1592 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1594 return ops
->vidioc_s_fmt_vid_out_mplane(file
, fh
, arg
);
1595 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
1596 if (unlikely(!ops
->vidioc_s_fmt_vid_out_overlay
))
1598 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1599 return ops
->vidioc_s_fmt_vid_out_overlay(file
, fh
, arg
);
1600 case V4L2_BUF_TYPE_VBI_OUTPUT
:
1601 if (unlikely(!ops
->vidioc_s_fmt_vbi_out
))
1603 CLEAR_AFTER_FIELD(p
, fmt
.vbi
);
1604 return ops
->vidioc_s_fmt_vbi_out(file
, fh
, arg
);
1605 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1606 if (unlikely(!ops
->vidioc_s_fmt_sliced_vbi_out
))
1608 CLEAR_AFTER_FIELD(p
, fmt
.sliced
);
1609 return ops
->vidioc_s_fmt_sliced_vbi_out(file
, fh
, arg
);
1610 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1611 if (unlikely(!ops
->vidioc_s_fmt_sdr_cap
))
1613 CLEAR_AFTER_FIELD(p
, fmt
.sdr
);
1614 return ops
->vidioc_s_fmt_sdr_cap(file
, fh
, arg
);
1615 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1616 if (unlikely(!ops
->vidioc_s_fmt_sdr_out
))
1618 CLEAR_AFTER_FIELD(p
, fmt
.sdr
);
1619 return ops
->vidioc_s_fmt_sdr_out(file
, fh
, arg
);
1620 case V4L2_BUF_TYPE_META_CAPTURE
:
1621 if (unlikely(!ops
->vidioc_s_fmt_meta_cap
))
1623 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1624 return ops
->vidioc_s_fmt_meta_cap(file
, fh
, arg
);
1625 case V4L2_BUF_TYPE_META_OUTPUT
:
1626 if (unlikely(!ops
->vidioc_s_fmt_meta_out
))
1628 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1629 return ops
->vidioc_s_fmt_meta_out(file
, fh
, arg
);
1634 static int v4l_try_fmt(const struct v4l2_ioctl_ops
*ops
,
1635 struct file
*file
, void *fh
, void *arg
)
1637 struct v4l2_format
*p
= arg
;
1638 int ret
= check_fmt(file
, p
->type
);
1644 v4l_sanitize_format(p
);
1647 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1648 if (unlikely(!ops
->vidioc_try_fmt_vid_cap
))
1650 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1651 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, arg
);
1652 /* just in case the driver zeroed it again */
1653 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1655 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1656 if (unlikely(!ops
->vidioc_try_fmt_vid_cap_mplane
))
1658 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1659 if (p
->fmt
.pix_mp
.num_planes
> VIDEO_MAX_PLANES
)
1661 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1662 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1664 return ops
->vidioc_try_fmt_vid_cap_mplane(file
, fh
, arg
);
1665 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1666 if (unlikely(!ops
->vidioc_try_fmt_vid_overlay
))
1668 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1669 return ops
->vidioc_try_fmt_vid_overlay(file
, fh
, arg
);
1670 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1671 if (unlikely(!ops
->vidioc_try_fmt_vbi_cap
))
1673 CLEAR_AFTER_FIELD(p
, fmt
.vbi
);
1674 return ops
->vidioc_try_fmt_vbi_cap(file
, fh
, arg
);
1675 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
1676 if (unlikely(!ops
->vidioc_try_fmt_sliced_vbi_cap
))
1678 CLEAR_AFTER_FIELD(p
, fmt
.sliced
);
1679 return ops
->vidioc_try_fmt_sliced_vbi_cap(file
, fh
, arg
);
1680 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1681 if (unlikely(!ops
->vidioc_try_fmt_vid_out
))
1683 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1684 ret
= ops
->vidioc_try_fmt_vid_out(file
, fh
, arg
);
1685 /* just in case the driver zeroed it again */
1686 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1688 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1689 if (unlikely(!ops
->vidioc_try_fmt_vid_out_mplane
))
1691 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1692 if (p
->fmt
.pix_mp
.num_planes
> VIDEO_MAX_PLANES
)
1694 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1695 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1697 return ops
->vidioc_try_fmt_vid_out_mplane(file
, fh
, arg
);
1698 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
1699 if (unlikely(!ops
->vidioc_try_fmt_vid_out_overlay
))
1701 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1702 return ops
->vidioc_try_fmt_vid_out_overlay(file
, fh
, arg
);
1703 case V4L2_BUF_TYPE_VBI_OUTPUT
:
1704 if (unlikely(!ops
->vidioc_try_fmt_vbi_out
))
1706 CLEAR_AFTER_FIELD(p
, fmt
.vbi
);
1707 return ops
->vidioc_try_fmt_vbi_out(file
, fh
, arg
);
1708 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1709 if (unlikely(!ops
->vidioc_try_fmt_sliced_vbi_out
))
1711 CLEAR_AFTER_FIELD(p
, fmt
.sliced
);
1712 return ops
->vidioc_try_fmt_sliced_vbi_out(file
, fh
, arg
);
1713 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1714 if (unlikely(!ops
->vidioc_try_fmt_sdr_cap
))
1716 CLEAR_AFTER_FIELD(p
, fmt
.sdr
);
1717 return ops
->vidioc_try_fmt_sdr_cap(file
, fh
, arg
);
1718 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1719 if (unlikely(!ops
->vidioc_try_fmt_sdr_out
))
1721 CLEAR_AFTER_FIELD(p
, fmt
.sdr
);
1722 return ops
->vidioc_try_fmt_sdr_out(file
, fh
, arg
);
1723 case V4L2_BUF_TYPE_META_CAPTURE
:
1724 if (unlikely(!ops
->vidioc_try_fmt_meta_cap
))
1726 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1727 return ops
->vidioc_try_fmt_meta_cap(file
, fh
, arg
);
1728 case V4L2_BUF_TYPE_META_OUTPUT
:
1729 if (unlikely(!ops
->vidioc_try_fmt_meta_out
))
1731 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1732 return ops
->vidioc_try_fmt_meta_out(file
, fh
, arg
);
1737 static int v4l_streamon(const struct v4l2_ioctl_ops
*ops
,
1738 struct file
*file
, void *fh
, void *arg
)
1740 return ops
->vidioc_streamon(file
, fh
, *(unsigned int *)arg
);
1743 static int v4l_streamoff(const struct v4l2_ioctl_ops
*ops
,
1744 struct file
*file
, void *fh
, void *arg
)
1746 return ops
->vidioc_streamoff(file
, fh
, *(unsigned int *)arg
);
1749 static int v4l_g_tuner(const struct v4l2_ioctl_ops
*ops
,
1750 struct file
*file
, void *fh
, void *arg
)
1752 struct video_device
*vfd
= video_devdata(file
);
1753 struct v4l2_tuner
*p
= arg
;
1756 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1757 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1758 err
= ops
->vidioc_g_tuner(file
, fh
, p
);
1760 p
->capability
|= V4L2_TUNER_CAP_FREQ_BANDS
;
1764 static int v4l_s_tuner(const struct v4l2_ioctl_ops
*ops
,
1765 struct file
*file
, void *fh
, void *arg
)
1767 struct video_device
*vfd
= video_devdata(file
);
1768 struct v4l2_tuner
*p
= arg
;
1771 ret
= v4l_enable_media_source(vfd
);
1774 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1775 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1776 return ops
->vidioc_s_tuner(file
, fh
, p
);
1779 static int v4l_g_modulator(const struct v4l2_ioctl_ops
*ops
,
1780 struct file
*file
, void *fh
, void *arg
)
1782 struct video_device
*vfd
= video_devdata(file
);
1783 struct v4l2_modulator
*p
= arg
;
1786 if (vfd
->vfl_type
== VFL_TYPE_RADIO
)
1787 p
->type
= V4L2_TUNER_RADIO
;
1789 err
= ops
->vidioc_g_modulator(file
, fh
, p
);
1791 p
->capability
|= V4L2_TUNER_CAP_FREQ_BANDS
;
1795 static int v4l_s_modulator(const struct v4l2_ioctl_ops
*ops
,
1796 struct file
*file
, void *fh
, void *arg
)
1798 struct video_device
*vfd
= video_devdata(file
);
1799 struct v4l2_modulator
*p
= arg
;
1801 if (vfd
->vfl_type
== VFL_TYPE_RADIO
)
1802 p
->type
= V4L2_TUNER_RADIO
;
1804 return ops
->vidioc_s_modulator(file
, fh
, p
);
1807 static int v4l_g_frequency(const struct v4l2_ioctl_ops
*ops
,
1808 struct file
*file
, void *fh
, void *arg
)
1810 struct video_device
*vfd
= video_devdata(file
);
1811 struct v4l2_frequency
*p
= arg
;
1813 if (vfd
->vfl_type
== VFL_TYPE_SDR
)
1814 p
->type
= V4L2_TUNER_SDR
;
1816 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1817 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1818 return ops
->vidioc_g_frequency(file
, fh
, p
);
1821 static int v4l_s_frequency(const struct v4l2_ioctl_ops
*ops
,
1822 struct file
*file
, void *fh
, void *arg
)
1824 struct video_device
*vfd
= video_devdata(file
);
1825 const struct v4l2_frequency
*p
= arg
;
1826 enum v4l2_tuner_type type
;
1829 ret
= v4l_enable_media_source(vfd
);
1832 if (vfd
->vfl_type
== VFL_TYPE_SDR
) {
1833 if (p
->type
!= V4L2_TUNER_SDR
&& p
->type
!= V4L2_TUNER_RF
)
1836 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1837 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1838 if (type
!= p
->type
)
1841 return ops
->vidioc_s_frequency(file
, fh
, p
);
1844 static int v4l_enumstd(const struct v4l2_ioctl_ops
*ops
,
1845 struct file
*file
, void *fh
, void *arg
)
1847 struct video_device
*vfd
= video_devdata(file
);
1848 struct v4l2_standard
*p
= arg
;
1850 return v4l_video_std_enumstd(p
, vfd
->tvnorms
);
1853 static int v4l_s_std(const struct v4l2_ioctl_ops
*ops
,
1854 struct file
*file
, void *fh
, void *arg
)
1856 struct video_device
*vfd
= video_devdata(file
);
1857 v4l2_std_id id
= *(v4l2_std_id
*)arg
, norm
;
1860 ret
= v4l_enable_media_source(vfd
);
1863 norm
= id
& vfd
->tvnorms
;
1864 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1867 /* Calls the specific handler */
1868 return ops
->vidioc_s_std(file
, fh
, norm
);
1871 static int v4l_querystd(const struct v4l2_ioctl_ops
*ops
,
1872 struct file
*file
, void *fh
, void *arg
)
1874 struct video_device
*vfd
= video_devdata(file
);
1875 v4l2_std_id
*p
= arg
;
1878 ret
= v4l_enable_media_source(vfd
);
1882 * If no signal is detected, then the driver should return
1883 * V4L2_STD_UNKNOWN. Otherwise it should return tvnorms with
1884 * any standards that do not apply removed.
1886 * This means that tuners, audio and video decoders can join
1887 * their efforts to improve the standards detection.
1890 return ops
->vidioc_querystd(file
, fh
, arg
);
1893 static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops
*ops
,
1894 struct file
*file
, void *fh
, void *arg
)
1896 struct video_device
*vfd
= video_devdata(file
);
1897 struct v4l2_hw_freq_seek
*p
= arg
;
1898 enum v4l2_tuner_type type
;
1901 ret
= v4l_enable_media_source(vfd
);
1904 /* s_hw_freq_seek is not supported for SDR for now */
1905 if (vfd
->vfl_type
== VFL_TYPE_SDR
)
1908 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1909 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1910 if (p
->type
!= type
)
1912 return ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
1915 static int v4l_overlay(const struct v4l2_ioctl_ops
*ops
,
1916 struct file
*file
, void *fh
, void *arg
)
1918 return ops
->vidioc_overlay(file
, fh
, *(unsigned int *)arg
);
1921 static int v4l_reqbufs(const struct v4l2_ioctl_ops
*ops
,
1922 struct file
*file
, void *fh
, void *arg
)
1924 struct v4l2_requestbuffers
*p
= arg
;
1925 int ret
= check_fmt(file
, p
->type
);
1930 CLEAR_AFTER_FIELD(p
, capabilities
);
1932 return ops
->vidioc_reqbufs(file
, fh
, p
);
1935 static int v4l_querybuf(const struct v4l2_ioctl_ops
*ops
,
1936 struct file
*file
, void *fh
, void *arg
)
1938 struct v4l2_buffer
*p
= arg
;
1939 int ret
= check_fmt(file
, p
->type
);
1941 return ret
? ret
: ops
->vidioc_querybuf(file
, fh
, p
);
1944 static int v4l_qbuf(const struct v4l2_ioctl_ops
*ops
,
1945 struct file
*file
, void *fh
, void *arg
)
1947 struct v4l2_buffer
*p
= arg
;
1948 int ret
= check_fmt(file
, p
->type
);
1950 return ret
? ret
: ops
->vidioc_qbuf(file
, fh
, p
);
1953 static int v4l_dqbuf(const struct v4l2_ioctl_ops
*ops
,
1954 struct file
*file
, void *fh
, void *arg
)
1956 struct v4l2_buffer
*p
= arg
;
1957 int ret
= check_fmt(file
, p
->type
);
1959 return ret
? ret
: ops
->vidioc_dqbuf(file
, fh
, p
);
1962 static int v4l_create_bufs(const struct v4l2_ioctl_ops
*ops
,
1963 struct file
*file
, void *fh
, void *arg
)
1965 struct v4l2_create_buffers
*create
= arg
;
1966 int ret
= check_fmt(file
, create
->format
.type
);
1971 CLEAR_AFTER_FIELD(create
, capabilities
);
1973 v4l_sanitize_format(&create
->format
);
1975 ret
= ops
->vidioc_create_bufs(file
, fh
, create
);
1977 if (create
->format
.type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
||
1978 create
->format
.type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1979 create
->format
.fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1984 static int v4l_prepare_buf(const struct v4l2_ioctl_ops
*ops
,
1985 struct file
*file
, void *fh
, void *arg
)
1987 struct v4l2_buffer
*b
= arg
;
1988 int ret
= check_fmt(file
, b
->type
);
1990 return ret
? ret
: ops
->vidioc_prepare_buf(file
, fh
, b
);
1993 static int v4l_g_parm(const struct v4l2_ioctl_ops
*ops
,
1994 struct file
*file
, void *fh
, void *arg
)
1996 struct v4l2_streamparm
*p
= arg
;
1998 int ret
= check_fmt(file
, p
->type
);
2002 if (ops
->vidioc_g_parm
)
2003 return ops
->vidioc_g_parm(file
, fh
, p
);
2004 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
2005 p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2007 p
->parm
.capture
.readbuffers
= 2;
2008 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
2010 v4l2_video_std_frame_period(std
, &p
->parm
.capture
.timeperframe
);
2014 static int v4l_s_parm(const struct v4l2_ioctl_ops
*ops
,
2015 struct file
*file
, void *fh
, void *arg
)
2017 struct v4l2_streamparm
*p
= arg
;
2018 int ret
= check_fmt(file
, p
->type
);
2023 /* Note: extendedmode is never used in drivers */
2024 if (V4L2_TYPE_IS_OUTPUT(p
->type
)) {
2025 memset(p
->parm
.output
.reserved
, 0,
2026 sizeof(p
->parm
.output
.reserved
));
2027 p
->parm
.output
.extendedmode
= 0;
2028 p
->parm
.output
.outputmode
&= V4L2_MODE_HIGHQUALITY
;
2030 memset(p
->parm
.capture
.reserved
, 0,
2031 sizeof(p
->parm
.capture
.reserved
));
2032 p
->parm
.capture
.extendedmode
= 0;
2033 p
->parm
.capture
.capturemode
&= V4L2_MODE_HIGHQUALITY
;
2035 return ops
->vidioc_s_parm(file
, fh
, p
);
2038 static int v4l_queryctrl(const struct v4l2_ioctl_ops
*ops
,
2039 struct file
*file
, void *fh
, void *arg
)
2041 struct video_device
*vfd
= video_devdata(file
);
2042 struct v4l2_queryctrl
*p
= arg
;
2043 struct v4l2_fh
*vfh
=
2044 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2046 if (vfh
&& vfh
->ctrl_handler
)
2047 return v4l2_queryctrl(vfh
->ctrl_handler
, p
);
2048 if (vfd
->ctrl_handler
)
2049 return v4l2_queryctrl(vfd
->ctrl_handler
, p
);
2050 if (ops
->vidioc_queryctrl
)
2051 return ops
->vidioc_queryctrl(file
, fh
, p
);
2055 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops
*ops
,
2056 struct file
*file
, void *fh
, void *arg
)
2058 struct video_device
*vfd
= video_devdata(file
);
2059 struct v4l2_query_ext_ctrl
*p
= arg
;
2060 struct v4l2_fh
*vfh
=
2061 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2063 if (vfh
&& vfh
->ctrl_handler
)
2064 return v4l2_query_ext_ctrl(vfh
->ctrl_handler
, p
);
2065 if (vfd
->ctrl_handler
)
2066 return v4l2_query_ext_ctrl(vfd
->ctrl_handler
, p
);
2067 if (ops
->vidioc_query_ext_ctrl
)
2068 return ops
->vidioc_query_ext_ctrl(file
, fh
, p
);
2072 static int v4l_querymenu(const struct v4l2_ioctl_ops
*ops
,
2073 struct file
*file
, void *fh
, void *arg
)
2075 struct video_device
*vfd
= video_devdata(file
);
2076 struct v4l2_querymenu
*p
= arg
;
2077 struct v4l2_fh
*vfh
=
2078 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2080 if (vfh
&& vfh
->ctrl_handler
)
2081 return v4l2_querymenu(vfh
->ctrl_handler
, p
);
2082 if (vfd
->ctrl_handler
)
2083 return v4l2_querymenu(vfd
->ctrl_handler
, p
);
2084 if (ops
->vidioc_querymenu
)
2085 return ops
->vidioc_querymenu(file
, fh
, p
);
2089 static int v4l_g_ctrl(const struct v4l2_ioctl_ops
*ops
,
2090 struct file
*file
, void *fh
, void *arg
)
2092 struct video_device
*vfd
= video_devdata(file
);
2093 struct v4l2_control
*p
= arg
;
2094 struct v4l2_fh
*vfh
=
2095 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2096 struct v4l2_ext_controls ctrls
;
2097 struct v4l2_ext_control ctrl
;
2099 if (vfh
&& vfh
->ctrl_handler
)
2100 return v4l2_g_ctrl(vfh
->ctrl_handler
, p
);
2101 if (vfd
->ctrl_handler
)
2102 return v4l2_g_ctrl(vfd
->ctrl_handler
, p
);
2103 if (ops
->vidioc_g_ctrl
)
2104 return ops
->vidioc_g_ctrl(file
, fh
, p
);
2105 if (ops
->vidioc_g_ext_ctrls
== NULL
)
2108 ctrls
.which
= V4L2_CTRL_ID2WHICH(p
->id
);
2110 ctrls
.controls
= &ctrl
;
2112 ctrl
.value
= p
->value
;
2113 if (check_ext_ctrls(&ctrls
, 1)) {
2114 int ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
2117 p
->value
= ctrl
.value
;
2123 static int v4l_s_ctrl(const struct v4l2_ioctl_ops
*ops
,
2124 struct file
*file
, void *fh
, void *arg
)
2126 struct video_device
*vfd
= video_devdata(file
);
2127 struct v4l2_control
*p
= arg
;
2128 struct v4l2_fh
*vfh
=
2129 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2130 struct v4l2_ext_controls ctrls
;
2131 struct v4l2_ext_control ctrl
;
2133 if (vfh
&& vfh
->ctrl_handler
)
2134 return v4l2_s_ctrl(vfh
, vfh
->ctrl_handler
, p
);
2135 if (vfd
->ctrl_handler
)
2136 return v4l2_s_ctrl(NULL
, vfd
->ctrl_handler
, p
);
2137 if (ops
->vidioc_s_ctrl
)
2138 return ops
->vidioc_s_ctrl(file
, fh
, p
);
2139 if (ops
->vidioc_s_ext_ctrls
== NULL
)
2142 ctrls
.which
= V4L2_CTRL_ID2WHICH(p
->id
);
2144 ctrls
.controls
= &ctrl
;
2146 ctrl
.value
= p
->value
;
2147 if (check_ext_ctrls(&ctrls
, 1))
2148 return ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
2152 static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops
*ops
,
2153 struct file
*file
, void *fh
, void *arg
)
2155 struct video_device
*vfd
= video_devdata(file
);
2156 struct v4l2_ext_controls
*p
= arg
;
2157 struct v4l2_fh
*vfh
=
2158 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2160 p
->error_idx
= p
->count
;
2161 if (vfh
&& vfh
->ctrl_handler
)
2162 return v4l2_g_ext_ctrls(vfh
->ctrl_handler
, vfd
->v4l2_dev
->mdev
, p
);
2163 if (vfd
->ctrl_handler
)
2164 return v4l2_g_ext_ctrls(vfd
->ctrl_handler
, vfd
->v4l2_dev
->mdev
, p
);
2165 if (ops
->vidioc_g_ext_ctrls
== NULL
)
2167 return check_ext_ctrls(p
, 0) ? ops
->vidioc_g_ext_ctrls(file
, fh
, p
) :
2171 static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops
*ops
,
2172 struct file
*file
, void *fh
, void *arg
)
2174 struct video_device
*vfd
= video_devdata(file
);
2175 struct v4l2_ext_controls
*p
= arg
;
2176 struct v4l2_fh
*vfh
=
2177 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2179 p
->error_idx
= p
->count
;
2180 if (vfh
&& vfh
->ctrl_handler
)
2181 return v4l2_s_ext_ctrls(vfh
, vfh
->ctrl_handler
, vfd
->v4l2_dev
->mdev
, p
);
2182 if (vfd
->ctrl_handler
)
2183 return v4l2_s_ext_ctrls(NULL
, vfd
->ctrl_handler
, vfd
->v4l2_dev
->mdev
, p
);
2184 if (ops
->vidioc_s_ext_ctrls
== NULL
)
2186 return check_ext_ctrls(p
, 0) ? ops
->vidioc_s_ext_ctrls(file
, fh
, p
) :
2190 static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops
*ops
,
2191 struct file
*file
, void *fh
, void *arg
)
2193 struct video_device
*vfd
= video_devdata(file
);
2194 struct v4l2_ext_controls
*p
= arg
;
2195 struct v4l2_fh
*vfh
=
2196 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2198 p
->error_idx
= p
->count
;
2199 if (vfh
&& vfh
->ctrl_handler
)
2200 return v4l2_try_ext_ctrls(vfh
->ctrl_handler
, vfd
->v4l2_dev
->mdev
, p
);
2201 if (vfd
->ctrl_handler
)
2202 return v4l2_try_ext_ctrls(vfd
->ctrl_handler
, vfd
->v4l2_dev
->mdev
, p
);
2203 if (ops
->vidioc_try_ext_ctrls
== NULL
)
2205 return check_ext_ctrls(p
, 0) ? ops
->vidioc_try_ext_ctrls(file
, fh
, p
) :
2210 * The selection API specified originally that the _MPLANE buffer types
2211 * shouldn't be used. The reasons for this are lost in the mists of time
2212 * (or just really crappy memories). Regardless, this is really annoying
2213 * for userspace. So to keep things simple we map _MPLANE buffer types
2214 * to their 'regular' counterparts before calling the driver. And we
2215 * restore it afterwards. This way applications can use either buffer
2216 * type and drivers don't need to check for both.
2218 static int v4l_g_selection(const struct v4l2_ioctl_ops
*ops
,
2219 struct file
*file
, void *fh
, void *arg
)
2221 struct v4l2_selection
*p
= arg
;
2222 u32 old_type
= p
->type
;
2225 if (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2226 p
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2227 else if (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
2228 p
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
2229 ret
= ops
->vidioc_g_selection(file
, fh
, p
);
2234 static int v4l_s_selection(const struct v4l2_ioctl_ops
*ops
,
2235 struct file
*file
, void *fh
, void *arg
)
2237 struct v4l2_selection
*p
= arg
;
2238 u32 old_type
= p
->type
;
2241 if (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2242 p
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2243 else if (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
2244 p
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
2245 ret
= ops
->vidioc_s_selection(file
, fh
, p
);
2250 static int v4l_g_crop(const struct v4l2_ioctl_ops
*ops
,
2251 struct file
*file
, void *fh
, void *arg
)
2253 struct video_device
*vfd
= video_devdata(file
);
2254 struct v4l2_crop
*p
= arg
;
2255 struct v4l2_selection s
= {
2260 /* simulate capture crop using selection api */
2262 /* crop means compose for output devices */
2263 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
2264 s
.target
= V4L2_SEL_TGT_COMPOSE
;
2266 s
.target
= V4L2_SEL_TGT_CROP
;
2268 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP
, &vfd
->flags
))
2269 s
.target
= s
.target
== V4L2_SEL_TGT_COMPOSE
?
2270 V4L2_SEL_TGT_CROP
: V4L2_SEL_TGT_COMPOSE
;
2272 ret
= v4l_g_selection(ops
, file
, fh
, &s
);
2274 /* copying results to old structure on success */
2280 static int v4l_s_crop(const struct v4l2_ioctl_ops
*ops
,
2281 struct file
*file
, void *fh
, void *arg
)
2283 struct video_device
*vfd
= video_devdata(file
);
2284 struct v4l2_crop
*p
= arg
;
2285 struct v4l2_selection s
= {
2290 /* simulate capture crop using selection api */
2292 /* crop means compose for output devices */
2293 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
2294 s
.target
= V4L2_SEL_TGT_COMPOSE
;
2296 s
.target
= V4L2_SEL_TGT_CROP
;
2298 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP
, &vfd
->flags
))
2299 s
.target
= s
.target
== V4L2_SEL_TGT_COMPOSE
?
2300 V4L2_SEL_TGT_CROP
: V4L2_SEL_TGT_COMPOSE
;
2302 return v4l_s_selection(ops
, file
, fh
, &s
);
2305 static int v4l_cropcap(const struct v4l2_ioctl_ops
*ops
,
2306 struct file
*file
, void *fh
, void *arg
)
2308 struct video_device
*vfd
= video_devdata(file
);
2309 struct v4l2_cropcap
*p
= arg
;
2310 struct v4l2_selection s
= { .type
= p
->type
};
2313 /* setting trivial pixelaspect */
2314 p
->pixelaspect
.numerator
= 1;
2315 p
->pixelaspect
.denominator
= 1;
2317 if (s
.type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2318 s
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2319 else if (s
.type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
2320 s
.type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
2323 * The determine_valid_ioctls() call already should ensure
2324 * that this can never happen, but just in case...
2326 if (WARN_ON(!ops
->vidioc_g_selection
))
2329 if (ops
->vidioc_g_pixelaspect
)
2330 ret
= ops
->vidioc_g_pixelaspect(file
, fh
, s
.type
,
2334 * Ignore ENOTTY or ENOIOCTLCMD error returns, just use the
2335 * square pixel aspect ratio in that case.
2337 if (ret
&& ret
!= -ENOTTY
&& ret
!= -ENOIOCTLCMD
)
2340 /* Use g_selection() to fill in the bounds and defrect rectangles */
2342 /* obtaining bounds */
2343 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
2344 s
.target
= V4L2_SEL_TGT_COMPOSE_BOUNDS
;
2346 s
.target
= V4L2_SEL_TGT_CROP_BOUNDS
;
2348 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP
, &vfd
->flags
))
2349 s
.target
= s
.target
== V4L2_SEL_TGT_COMPOSE_BOUNDS
?
2350 V4L2_SEL_TGT_CROP_BOUNDS
: V4L2_SEL_TGT_COMPOSE_BOUNDS
;
2352 ret
= v4l_g_selection(ops
, file
, fh
, &s
);
2357 /* obtaining defrect */
2358 if (s
.target
== V4L2_SEL_TGT_COMPOSE_BOUNDS
)
2359 s
.target
= V4L2_SEL_TGT_COMPOSE_DEFAULT
;
2361 s
.target
= V4L2_SEL_TGT_CROP_DEFAULT
;
2363 ret
= v4l_g_selection(ops
, file
, fh
, &s
);
2371 static int v4l_log_status(const struct v4l2_ioctl_ops
*ops
,
2372 struct file
*file
, void *fh
, void *arg
)
2374 struct video_device
*vfd
= video_devdata(file
);
2378 pr_info("%s: ================= START STATUS =================\n",
2379 vfd
->v4l2_dev
->name
);
2380 ret
= ops
->vidioc_log_status(file
, fh
);
2382 pr_info("%s: ================== END STATUS ==================\n",
2383 vfd
->v4l2_dev
->name
);
2387 static int v4l_dbg_g_register(const struct v4l2_ioctl_ops
*ops
,
2388 struct file
*file
, void *fh
, void *arg
)
2390 #ifdef CONFIG_VIDEO_ADV_DEBUG
2391 struct v4l2_dbg_register
*p
= arg
;
2392 struct video_device
*vfd
= video_devdata(file
);
2393 struct v4l2_subdev
*sd
;
2396 if (!capable(CAP_SYS_ADMIN
))
2398 if (p
->match
.type
== V4L2_CHIP_MATCH_SUBDEV
) {
2399 if (vfd
->v4l2_dev
== NULL
)
2401 v4l2_device_for_each_subdev(sd
, vfd
->v4l2_dev
)
2402 if (p
->match
.addr
== idx
++)
2403 return v4l2_subdev_call(sd
, core
, g_register
, p
);
2406 if (ops
->vidioc_g_register
&& p
->match
.type
== V4L2_CHIP_MATCH_BRIDGE
&&
2407 (ops
->vidioc_g_chip_info
|| p
->match
.addr
== 0))
2408 return ops
->vidioc_g_register(file
, fh
, p
);
2415 static int v4l_dbg_s_register(const struct v4l2_ioctl_ops
*ops
,
2416 struct file
*file
, void *fh
, void *arg
)
2418 #ifdef CONFIG_VIDEO_ADV_DEBUG
2419 const struct v4l2_dbg_register
*p
= arg
;
2420 struct video_device
*vfd
= video_devdata(file
);
2421 struct v4l2_subdev
*sd
;
2424 if (!capable(CAP_SYS_ADMIN
))
2426 if (p
->match
.type
== V4L2_CHIP_MATCH_SUBDEV
) {
2427 if (vfd
->v4l2_dev
== NULL
)
2429 v4l2_device_for_each_subdev(sd
, vfd
->v4l2_dev
)
2430 if (p
->match
.addr
== idx
++)
2431 return v4l2_subdev_call(sd
, core
, s_register
, p
);
2434 if (ops
->vidioc_s_register
&& p
->match
.type
== V4L2_CHIP_MATCH_BRIDGE
&&
2435 (ops
->vidioc_g_chip_info
|| p
->match
.addr
== 0))
2436 return ops
->vidioc_s_register(file
, fh
, p
);
2443 static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops
*ops
,
2444 struct file
*file
, void *fh
, void *arg
)
2446 #ifdef CONFIG_VIDEO_ADV_DEBUG
2447 struct video_device
*vfd
= video_devdata(file
);
2448 struct v4l2_dbg_chip_info
*p
= arg
;
2449 struct v4l2_subdev
*sd
;
2452 switch (p
->match
.type
) {
2453 case V4L2_CHIP_MATCH_BRIDGE
:
2454 if (ops
->vidioc_s_register
)
2455 p
->flags
|= V4L2_CHIP_FL_WRITABLE
;
2456 if (ops
->vidioc_g_register
)
2457 p
->flags
|= V4L2_CHIP_FL_READABLE
;
2458 strscpy(p
->name
, vfd
->v4l2_dev
->name
, sizeof(p
->name
));
2459 if (ops
->vidioc_g_chip_info
)
2460 return ops
->vidioc_g_chip_info(file
, fh
, arg
);
2465 case V4L2_CHIP_MATCH_SUBDEV
:
2466 if (vfd
->v4l2_dev
== NULL
)
2468 v4l2_device_for_each_subdev(sd
, vfd
->v4l2_dev
) {
2469 if (p
->match
.addr
!= idx
++)
2471 if (sd
->ops
->core
&& sd
->ops
->core
->s_register
)
2472 p
->flags
|= V4L2_CHIP_FL_WRITABLE
;
2473 if (sd
->ops
->core
&& sd
->ops
->core
->g_register
)
2474 p
->flags
|= V4L2_CHIP_FL_READABLE
;
2475 strscpy(p
->name
, sd
->name
, sizeof(p
->name
));
2486 static int v4l_dqevent(const struct v4l2_ioctl_ops
*ops
,
2487 struct file
*file
, void *fh
, void *arg
)
2489 return v4l2_event_dequeue(fh
, arg
, file
->f_flags
& O_NONBLOCK
);
2492 static int v4l_subscribe_event(const struct v4l2_ioctl_ops
*ops
,
2493 struct file
*file
, void *fh
, void *arg
)
2495 return ops
->vidioc_subscribe_event(fh
, arg
);
2498 static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops
*ops
,
2499 struct file
*file
, void *fh
, void *arg
)
2501 return ops
->vidioc_unsubscribe_event(fh
, arg
);
2504 static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops
*ops
,
2505 struct file
*file
, void *fh
, void *arg
)
2507 struct v4l2_sliced_vbi_cap
*p
= arg
;
2508 int ret
= check_fmt(file
, p
->type
);
2513 /* Clear up to type, everything after type is zeroed already */
2514 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
2516 return ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
2519 static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops
*ops
,
2520 struct file
*file
, void *fh
, void *arg
)
2522 struct video_device
*vfd
= video_devdata(file
);
2523 struct v4l2_frequency_band
*p
= arg
;
2524 enum v4l2_tuner_type type
;
2527 if (vfd
->vfl_type
== VFL_TYPE_SDR
) {
2528 if (p
->type
!= V4L2_TUNER_SDR
&& p
->type
!= V4L2_TUNER_RF
)
2532 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
2533 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
2534 if (type
!= p
->type
)
2537 if (ops
->vidioc_enum_freq_bands
) {
2538 err
= ops
->vidioc_enum_freq_bands(file
, fh
, p
);
2542 if (is_valid_ioctl(vfd
, VIDIOC_G_TUNER
)) {
2543 struct v4l2_tuner t
= {
2550 err
= ops
->vidioc_g_tuner(file
, fh
, &t
);
2553 p
->capability
= t
.capability
| V4L2_TUNER_CAP_FREQ_BANDS
;
2554 p
->rangelow
= t
.rangelow
;
2555 p
->rangehigh
= t
.rangehigh
;
2556 p
->modulation
= (type
== V4L2_TUNER_RADIO
) ?
2557 V4L2_BAND_MODULATION_FM
: V4L2_BAND_MODULATION_VSB
;
2560 if (is_valid_ioctl(vfd
, VIDIOC_G_MODULATOR
)) {
2561 struct v4l2_modulator m
= {
2565 if (type
!= V4L2_TUNER_RADIO
)
2569 err
= ops
->vidioc_g_modulator(file
, fh
, &m
);
2572 p
->capability
= m
.capability
| V4L2_TUNER_CAP_FREQ_BANDS
;
2573 p
->rangelow
= m
.rangelow
;
2574 p
->rangehigh
= m
.rangehigh
;
2575 p
->modulation
= (type
== V4L2_TUNER_RADIO
) ?
2576 V4L2_BAND_MODULATION_FM
: V4L2_BAND_MODULATION_VSB
;
2582 struct v4l2_ioctl_info
{
2585 const char * const name
;
2586 int (*func
)(const struct v4l2_ioctl_ops
*ops
, struct file
*file
,
2588 void (*debug
)(const void *arg
, bool write_only
);
2591 /* This control needs a priority check */
2592 #define INFO_FL_PRIO (1 << 0)
2593 /* This control can be valid if the filehandle passes a control handler. */
2594 #define INFO_FL_CTRL (1 << 1)
2596 #define INFO_FL_QUEUE (1 << 2)
2597 /* Always copy back result, even on error */
2598 #define INFO_FL_ALWAYS_COPY (1 << 3)
2599 /* Zero struct from after the field to the end */
2600 #define INFO_FL_CLEAR(v4l2_struct, field) \
2601 ((offsetof(struct v4l2_struct, field) + \
2602 sizeof(((struct v4l2_struct *)0)->field)) << 16)
2603 #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
2605 #define DEFINE_V4L_STUB_FUNC(_vidioc) \
2606 static int v4l_stub_ ## _vidioc( \
2607 const struct v4l2_ioctl_ops *ops, \
2608 struct file *file, void *fh, void *p) \
2610 return ops->vidioc_ ## _vidioc(file, fh, p); \
2613 #define IOCTL_INFO(_ioctl, _func, _debug, _flags) \
2614 [_IOC_NR(_ioctl)] = { \
2622 DEFINE_V4L_STUB_FUNC(g_fbuf
)
2623 DEFINE_V4L_STUB_FUNC(s_fbuf
)
2624 DEFINE_V4L_STUB_FUNC(expbuf
)
2625 DEFINE_V4L_STUB_FUNC(g_std
)
2626 DEFINE_V4L_STUB_FUNC(g_audio
)
2627 DEFINE_V4L_STUB_FUNC(s_audio
)
2628 DEFINE_V4L_STUB_FUNC(g_input
)
2629 DEFINE_V4L_STUB_FUNC(g_edid
)
2630 DEFINE_V4L_STUB_FUNC(s_edid
)
2631 DEFINE_V4L_STUB_FUNC(g_output
)
2632 DEFINE_V4L_STUB_FUNC(g_audout
)
2633 DEFINE_V4L_STUB_FUNC(s_audout
)
2634 DEFINE_V4L_STUB_FUNC(g_jpegcomp
)
2635 DEFINE_V4L_STUB_FUNC(s_jpegcomp
)
2636 DEFINE_V4L_STUB_FUNC(enumaudio
)
2637 DEFINE_V4L_STUB_FUNC(enumaudout
)
2638 DEFINE_V4L_STUB_FUNC(enum_framesizes
)
2639 DEFINE_V4L_STUB_FUNC(enum_frameintervals
)
2640 DEFINE_V4L_STUB_FUNC(g_enc_index
)
2641 DEFINE_V4L_STUB_FUNC(encoder_cmd
)
2642 DEFINE_V4L_STUB_FUNC(try_encoder_cmd
)
2643 DEFINE_V4L_STUB_FUNC(decoder_cmd
)
2644 DEFINE_V4L_STUB_FUNC(try_decoder_cmd
)
2645 DEFINE_V4L_STUB_FUNC(s_dv_timings
)
2646 DEFINE_V4L_STUB_FUNC(g_dv_timings
)
2647 DEFINE_V4L_STUB_FUNC(enum_dv_timings
)
2648 DEFINE_V4L_STUB_FUNC(query_dv_timings
)
2649 DEFINE_V4L_STUB_FUNC(dv_timings_cap
)
2651 static const struct v4l2_ioctl_info v4l2_ioctls
[] = {
2652 IOCTL_INFO(VIDIOC_QUERYCAP
, v4l_querycap
, v4l_print_querycap
, 0),
2653 IOCTL_INFO(VIDIOC_ENUM_FMT
, v4l_enum_fmt
, v4l_print_fmtdesc
, INFO_FL_CLEAR(v4l2_fmtdesc
, type
)),
2654 IOCTL_INFO(VIDIOC_G_FMT
, v4l_g_fmt
, v4l_print_format
, 0),
2655 IOCTL_INFO(VIDIOC_S_FMT
, v4l_s_fmt
, v4l_print_format
, INFO_FL_PRIO
),
2656 IOCTL_INFO(VIDIOC_REQBUFS
, v4l_reqbufs
, v4l_print_requestbuffers
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2657 IOCTL_INFO(VIDIOC_QUERYBUF
, v4l_querybuf
, v4l_print_buffer
, INFO_FL_QUEUE
| INFO_FL_CLEAR(v4l2_buffer
, length
)),
2658 IOCTL_INFO(VIDIOC_G_FBUF
, v4l_stub_g_fbuf
, v4l_print_framebuffer
, 0),
2659 IOCTL_INFO(VIDIOC_S_FBUF
, v4l_stub_s_fbuf
, v4l_print_framebuffer
, INFO_FL_PRIO
),
2660 IOCTL_INFO(VIDIOC_OVERLAY
, v4l_overlay
, v4l_print_u32
, INFO_FL_PRIO
),
2661 IOCTL_INFO(VIDIOC_QBUF
, v4l_qbuf
, v4l_print_buffer
, INFO_FL_QUEUE
),
2662 IOCTL_INFO(VIDIOC_EXPBUF
, v4l_stub_expbuf
, v4l_print_exportbuffer
, INFO_FL_QUEUE
| INFO_FL_CLEAR(v4l2_exportbuffer
, flags
)),
2663 IOCTL_INFO(VIDIOC_DQBUF
, v4l_dqbuf
, v4l_print_buffer
, INFO_FL_QUEUE
),
2664 IOCTL_INFO(VIDIOC_STREAMON
, v4l_streamon
, v4l_print_buftype
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2665 IOCTL_INFO(VIDIOC_STREAMOFF
, v4l_streamoff
, v4l_print_buftype
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2666 IOCTL_INFO(VIDIOC_G_PARM
, v4l_g_parm
, v4l_print_streamparm
, INFO_FL_CLEAR(v4l2_streamparm
, type
)),
2667 IOCTL_INFO(VIDIOC_S_PARM
, v4l_s_parm
, v4l_print_streamparm
, INFO_FL_PRIO
),
2668 IOCTL_INFO(VIDIOC_G_STD
, v4l_stub_g_std
, v4l_print_std
, 0),
2669 IOCTL_INFO(VIDIOC_S_STD
, v4l_s_std
, v4l_print_std
, INFO_FL_PRIO
),
2670 IOCTL_INFO(VIDIOC_ENUMSTD
, v4l_enumstd
, v4l_print_standard
, INFO_FL_CLEAR(v4l2_standard
, index
)),
2671 IOCTL_INFO(VIDIOC_ENUMINPUT
, v4l_enuminput
, v4l_print_enuminput
, INFO_FL_CLEAR(v4l2_input
, index
)),
2672 IOCTL_INFO(VIDIOC_G_CTRL
, v4l_g_ctrl
, v4l_print_control
, INFO_FL_CTRL
| INFO_FL_CLEAR(v4l2_control
, id
)),
2673 IOCTL_INFO(VIDIOC_S_CTRL
, v4l_s_ctrl
, v4l_print_control
, INFO_FL_PRIO
| INFO_FL_CTRL
),
2674 IOCTL_INFO(VIDIOC_G_TUNER
, v4l_g_tuner
, v4l_print_tuner
, INFO_FL_CLEAR(v4l2_tuner
, index
)),
2675 IOCTL_INFO(VIDIOC_S_TUNER
, v4l_s_tuner
, v4l_print_tuner
, INFO_FL_PRIO
),
2676 IOCTL_INFO(VIDIOC_G_AUDIO
, v4l_stub_g_audio
, v4l_print_audio
, 0),
2677 IOCTL_INFO(VIDIOC_S_AUDIO
, v4l_stub_s_audio
, v4l_print_audio
, INFO_FL_PRIO
),
2678 IOCTL_INFO(VIDIOC_QUERYCTRL
, v4l_queryctrl
, v4l_print_queryctrl
, INFO_FL_CTRL
| INFO_FL_CLEAR(v4l2_queryctrl
, id
)),
2679 IOCTL_INFO(VIDIOC_QUERYMENU
, v4l_querymenu
, v4l_print_querymenu
, INFO_FL_CTRL
| INFO_FL_CLEAR(v4l2_querymenu
, index
)),
2680 IOCTL_INFO(VIDIOC_G_INPUT
, v4l_stub_g_input
, v4l_print_u32
, 0),
2681 IOCTL_INFO(VIDIOC_S_INPUT
, v4l_s_input
, v4l_print_u32
, INFO_FL_PRIO
),
2682 IOCTL_INFO(VIDIOC_G_EDID
, v4l_stub_g_edid
, v4l_print_edid
, INFO_FL_ALWAYS_COPY
),
2683 IOCTL_INFO(VIDIOC_S_EDID
, v4l_stub_s_edid
, v4l_print_edid
, INFO_FL_PRIO
| INFO_FL_ALWAYS_COPY
),
2684 IOCTL_INFO(VIDIOC_G_OUTPUT
, v4l_stub_g_output
, v4l_print_u32
, 0),
2685 IOCTL_INFO(VIDIOC_S_OUTPUT
, v4l_s_output
, v4l_print_u32
, INFO_FL_PRIO
),
2686 IOCTL_INFO(VIDIOC_ENUMOUTPUT
, v4l_enumoutput
, v4l_print_enumoutput
, INFO_FL_CLEAR(v4l2_output
, index
)),
2687 IOCTL_INFO(VIDIOC_G_AUDOUT
, v4l_stub_g_audout
, v4l_print_audioout
, 0),
2688 IOCTL_INFO(VIDIOC_S_AUDOUT
, v4l_stub_s_audout
, v4l_print_audioout
, INFO_FL_PRIO
),
2689 IOCTL_INFO(VIDIOC_G_MODULATOR
, v4l_g_modulator
, v4l_print_modulator
, INFO_FL_CLEAR(v4l2_modulator
, index
)),
2690 IOCTL_INFO(VIDIOC_S_MODULATOR
, v4l_s_modulator
, v4l_print_modulator
, INFO_FL_PRIO
),
2691 IOCTL_INFO(VIDIOC_G_FREQUENCY
, v4l_g_frequency
, v4l_print_frequency
, INFO_FL_CLEAR(v4l2_frequency
, tuner
)),
2692 IOCTL_INFO(VIDIOC_S_FREQUENCY
, v4l_s_frequency
, v4l_print_frequency
, INFO_FL_PRIO
),
2693 IOCTL_INFO(VIDIOC_CROPCAP
, v4l_cropcap
, v4l_print_cropcap
, INFO_FL_CLEAR(v4l2_cropcap
, type
)),
2694 IOCTL_INFO(VIDIOC_G_CROP
, v4l_g_crop
, v4l_print_crop
, INFO_FL_CLEAR(v4l2_crop
, type
)),
2695 IOCTL_INFO(VIDIOC_S_CROP
, v4l_s_crop
, v4l_print_crop
, INFO_FL_PRIO
),
2696 IOCTL_INFO(VIDIOC_G_SELECTION
, v4l_g_selection
, v4l_print_selection
, INFO_FL_CLEAR(v4l2_selection
, r
)),
2697 IOCTL_INFO(VIDIOC_S_SELECTION
, v4l_s_selection
, v4l_print_selection
, INFO_FL_PRIO
| INFO_FL_CLEAR(v4l2_selection
, r
)),
2698 IOCTL_INFO(VIDIOC_G_JPEGCOMP
, v4l_stub_g_jpegcomp
, v4l_print_jpegcompression
, 0),
2699 IOCTL_INFO(VIDIOC_S_JPEGCOMP
, v4l_stub_s_jpegcomp
, v4l_print_jpegcompression
, INFO_FL_PRIO
),
2700 IOCTL_INFO(VIDIOC_QUERYSTD
, v4l_querystd
, v4l_print_std
, 0),
2701 IOCTL_INFO(VIDIOC_TRY_FMT
, v4l_try_fmt
, v4l_print_format
, 0),
2702 IOCTL_INFO(VIDIOC_ENUMAUDIO
, v4l_stub_enumaudio
, v4l_print_audio
, INFO_FL_CLEAR(v4l2_audio
, index
)),
2703 IOCTL_INFO(VIDIOC_ENUMAUDOUT
, v4l_stub_enumaudout
, v4l_print_audioout
, INFO_FL_CLEAR(v4l2_audioout
, index
)),
2704 IOCTL_INFO(VIDIOC_G_PRIORITY
, v4l_g_priority
, v4l_print_u32
, 0),
2705 IOCTL_INFO(VIDIOC_S_PRIORITY
, v4l_s_priority
, v4l_print_u32
, INFO_FL_PRIO
),
2706 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
)),
2707 IOCTL_INFO(VIDIOC_LOG_STATUS
, v4l_log_status
, v4l_print_newline
, 0),
2708 IOCTL_INFO(VIDIOC_G_EXT_CTRLS
, v4l_g_ext_ctrls
, v4l_print_ext_controls
, INFO_FL_CTRL
),
2709 IOCTL_INFO(VIDIOC_S_EXT_CTRLS
, v4l_s_ext_ctrls
, v4l_print_ext_controls
, INFO_FL_PRIO
| INFO_FL_CTRL
),
2710 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS
, v4l_try_ext_ctrls
, v4l_print_ext_controls
, INFO_FL_CTRL
),
2711 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES
, v4l_stub_enum_framesizes
, v4l_print_frmsizeenum
, INFO_FL_CLEAR(v4l2_frmsizeenum
, pixel_format
)),
2712 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS
, v4l_stub_enum_frameintervals
, v4l_print_frmivalenum
, INFO_FL_CLEAR(v4l2_frmivalenum
, height
)),
2713 IOCTL_INFO(VIDIOC_G_ENC_INDEX
, v4l_stub_g_enc_index
, v4l_print_enc_idx
, 0),
2714 IOCTL_INFO(VIDIOC_ENCODER_CMD
, v4l_stub_encoder_cmd
, v4l_print_encoder_cmd
, INFO_FL_PRIO
| INFO_FL_CLEAR(v4l2_encoder_cmd
, flags
)),
2715 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD
, v4l_stub_try_encoder_cmd
, v4l_print_encoder_cmd
, INFO_FL_CLEAR(v4l2_encoder_cmd
, flags
)),
2716 IOCTL_INFO(VIDIOC_DECODER_CMD
, v4l_stub_decoder_cmd
, v4l_print_decoder_cmd
, INFO_FL_PRIO
),
2717 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD
, v4l_stub_try_decoder_cmd
, v4l_print_decoder_cmd
, 0),
2718 IOCTL_INFO(VIDIOC_DBG_S_REGISTER
, v4l_dbg_s_register
, v4l_print_dbg_register
, 0),
2719 IOCTL_INFO(VIDIOC_DBG_G_REGISTER
, v4l_dbg_g_register
, v4l_print_dbg_register
, 0),
2720 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK
, v4l_s_hw_freq_seek
, v4l_print_hw_freq_seek
, INFO_FL_PRIO
),
2721 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
)),
2722 IOCTL_INFO(VIDIOC_G_DV_TIMINGS
, v4l_stub_g_dv_timings
, v4l_print_dv_timings
, 0),
2723 IOCTL_INFO(VIDIOC_DQEVENT
, v4l_dqevent
, v4l_print_event
, 0),
2724 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT
, v4l_subscribe_event
, v4l_print_event_subscription
, 0),
2725 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT
, v4l_unsubscribe_event
, v4l_print_event_subscription
, 0),
2726 IOCTL_INFO(VIDIOC_CREATE_BUFS
, v4l_create_bufs
, v4l_print_create_buffers
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2727 IOCTL_INFO(VIDIOC_PREPARE_BUF
, v4l_prepare_buf
, v4l_print_buffer
, INFO_FL_QUEUE
),
2728 IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS
, v4l_stub_enum_dv_timings
, v4l_print_enum_dv_timings
, INFO_FL_CLEAR(v4l2_enum_dv_timings
, pad
)),
2729 IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS
, v4l_stub_query_dv_timings
, v4l_print_dv_timings
, INFO_FL_ALWAYS_COPY
),
2730 IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP
, v4l_stub_dv_timings_cap
, v4l_print_dv_timings_cap
, INFO_FL_CLEAR(v4l2_dv_timings_cap
, pad
)),
2731 IOCTL_INFO(VIDIOC_ENUM_FREQ_BANDS
, v4l_enum_freq_bands
, v4l_print_freq_band
, 0),
2732 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
)),
2733 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
)),
2735 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
2737 static bool v4l2_is_known_ioctl(unsigned int cmd
)
2739 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
)
2741 return v4l2_ioctls
[_IOC_NR(cmd
)].ioctl
== cmd
;
2744 static struct mutex
*v4l2_ioctl_get_lock(struct video_device
*vdev
,
2745 struct v4l2_fh
*vfh
, unsigned int cmd
,
2748 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
)
2750 #if IS_ENABLED(CONFIG_V4L2_MEM2MEM_DEV)
2751 if (vfh
&& vfh
->m2m_ctx
&&
2752 (v4l2_ioctls
[_IOC_NR(cmd
)].flags
& INFO_FL_QUEUE
)) {
2753 if (vfh
->m2m_ctx
->q_lock
)
2754 return vfh
->m2m_ctx
->q_lock
;
2757 if (vdev
->queue
&& vdev
->queue
->lock
&&
2758 (v4l2_ioctls
[_IOC_NR(cmd
)].flags
& INFO_FL_QUEUE
))
2759 return vdev
->queue
->lock
;
2763 /* Common ioctl debug function. This function can be used by
2764 external ioctl messages as well as internal V4L ioctl */
2765 void v4l_printk_ioctl(const char *prefix
, unsigned int cmd
)
2767 const char *dir
, *type
;
2770 printk(KERN_DEBUG
"%s: ", prefix
);
2772 switch (_IOC_TYPE(cmd
)) {
2777 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
2781 pr_cont("%s", v4l2_ioctls
[_IOC_NR(cmd
)].name
);
2788 switch (_IOC_DIR(cmd
)) {
2789 case _IOC_NONE
: dir
= "--"; break;
2790 case _IOC_READ
: dir
= "r-"; break;
2791 case _IOC_WRITE
: dir
= "-w"; break;
2792 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
2793 default: dir
= "*ERR*"; break;
2795 pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
2796 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
2798 EXPORT_SYMBOL(v4l_printk_ioctl
);
2800 static long __video_do_ioctl(struct file
*file
,
2801 unsigned int cmd
, void *arg
)
2803 struct video_device
*vfd
= video_devdata(file
);
2804 struct mutex
*req_queue_lock
= NULL
;
2805 struct mutex
*lock
; /* ioctl serialization mutex */
2806 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
2807 bool write_only
= false;
2808 struct v4l2_ioctl_info default_info
;
2809 const struct v4l2_ioctl_info
*info
;
2810 void *fh
= file
->private_data
;
2811 struct v4l2_fh
*vfh
= NULL
;
2812 int dev_debug
= vfd
->dev_debug
;
2816 pr_warn("%s: has no ioctl_ops.\n",
2817 video_device_node_name(vfd
));
2821 if (test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
))
2822 vfh
= file
->private_data
;
2825 * We need to serialize streamon/off with queueing new requests.
2826 * These ioctls may trigger the cancellation of a streaming
2827 * operation, and that should not be mixed with queueing a new
2828 * request at the same time.
2830 if (v4l2_device_supports_requests(vfd
->v4l2_dev
) &&
2831 (cmd
== VIDIOC_STREAMON
|| cmd
== VIDIOC_STREAMOFF
)) {
2832 req_queue_lock
= &vfd
->v4l2_dev
->mdev
->req_queue_mutex
;
2834 if (mutex_lock_interruptible(req_queue_lock
))
2835 return -ERESTARTSYS
;
2838 lock
= v4l2_ioctl_get_lock(vfd
, vfh
, cmd
, arg
);
2840 if (lock
&& mutex_lock_interruptible(lock
)) {
2842 mutex_unlock(req_queue_lock
);
2843 return -ERESTARTSYS
;
2846 if (!video_is_registered(vfd
)) {
2851 if (v4l2_is_known_ioctl(cmd
)) {
2852 info
= &v4l2_ioctls
[_IOC_NR(cmd
)];
2854 if (!test_bit(_IOC_NR(cmd
), vfd
->valid_ioctls
) &&
2855 !((info
->flags
& INFO_FL_CTRL
) && vfh
&& vfh
->ctrl_handler
))
2858 if (vfh
&& (info
->flags
& INFO_FL_PRIO
)) {
2859 ret
= v4l2_prio_check(vfd
->prio
, vfh
->prio
);
2864 default_info
.ioctl
= cmd
;
2865 default_info
.flags
= 0;
2866 default_info
.debug
= v4l_print_default
;
2867 info
= &default_info
;
2870 write_only
= _IOC_DIR(cmd
) == _IOC_WRITE
;
2871 if (info
!= &default_info
) {
2872 ret
= info
->func(ops
, file
, fh
, arg
);
2873 } else if (!ops
->vidioc_default
) {
2876 ret
= ops
->vidioc_default(file
, fh
,
2877 vfh
? v4l2_prio_check(vfd
->prio
, vfh
->prio
) >= 0 : 0,
2882 if (dev_debug
& (V4L2_DEV_DEBUG_IOCTL
| V4L2_DEV_DEBUG_IOCTL_ARG
)) {
2883 if (!(dev_debug
& V4L2_DEV_DEBUG_STREAMING
) &&
2884 (cmd
== VIDIOC_QBUF
|| cmd
== VIDIOC_DQBUF
))
2887 v4l_printk_ioctl(video_device_node_name(vfd
), cmd
);
2889 pr_cont(": error %ld", ret
);
2890 if (!(dev_debug
& V4L2_DEV_DEBUG_IOCTL_ARG
))
2892 else if (_IOC_DIR(cmd
) == _IOC_NONE
)
2893 info
->debug(arg
, write_only
);
2896 info
->debug(arg
, write_only
);
2904 mutex_unlock(req_queue_lock
);
2908 static int check_array_args(unsigned int cmd
, void *parg
, size_t *array_size
,
2909 void __user
**user_ptr
, void ***kernel_ptr
)
2914 case VIDIOC_PREPARE_BUF
:
2915 case VIDIOC_QUERYBUF
:
2917 case VIDIOC_DQBUF
: {
2918 struct v4l2_buffer
*buf
= parg
;
2920 if (V4L2_TYPE_IS_MULTIPLANAR(buf
->type
) && buf
->length
> 0) {
2921 if (buf
->length
> VIDEO_MAX_PLANES
) {
2925 *user_ptr
= (void __user
*)buf
->m
.planes
;
2926 *kernel_ptr
= (void **)&buf
->m
.planes
;
2927 *array_size
= sizeof(struct v4l2_plane
) * buf
->length
;
2934 case VIDIOC_S_EDID
: {
2935 struct v4l2_edid
*edid
= parg
;
2938 if (edid
->blocks
> 256) {
2942 *user_ptr
= (void __user
*)edid
->edid
;
2943 *kernel_ptr
= (void **)&edid
->edid
;
2944 *array_size
= edid
->blocks
* 128;
2950 case VIDIOC_S_EXT_CTRLS
:
2951 case VIDIOC_G_EXT_CTRLS
:
2952 case VIDIOC_TRY_EXT_CTRLS
: {
2953 struct v4l2_ext_controls
*ctrls
= parg
;
2955 if (ctrls
->count
!= 0) {
2956 if (ctrls
->count
> V4L2_CID_MAX_CTRLS
) {
2960 *user_ptr
= (void __user
*)ctrls
->controls
;
2961 *kernel_ptr
= (void **)&ctrls
->controls
;
2962 *array_size
= sizeof(struct v4l2_ext_control
)
2974 video_usercopy(struct file
*file
, unsigned int cmd
, unsigned long arg
,
2979 void *parg
= (void *)arg
;
2981 bool has_array_args
;
2982 bool always_copy
= false;
2983 size_t array_size
= 0;
2984 void __user
*user_ptr
= NULL
;
2985 void **kernel_ptr
= NULL
;
2986 const size_t ioc_size
= _IOC_SIZE(cmd
);
2988 /* Copy arguments into temp kernel buffer */
2989 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
2990 if (ioc_size
<= sizeof(sbuf
)) {
2993 /* too big to allocate from stack */
2994 mbuf
= kvmalloc(ioc_size
, GFP_KERNEL
);
3001 if (_IOC_DIR(cmd
) & _IOC_WRITE
) {
3002 unsigned int n
= ioc_size
;
3005 * In some cases, only a few fields are used as input,
3006 * i.e. when the app sets "index" and then the driver
3007 * fills in the rest of the structure for the thing
3008 * with that index. We only need to copy up the first
3011 if (v4l2_is_known_ioctl(cmd
)) {
3012 u32 flags
= v4l2_ioctls
[_IOC_NR(cmd
)].flags
;
3014 if (flags
& INFO_FL_CLEAR_MASK
)
3015 n
= (flags
& INFO_FL_CLEAR_MASK
) >> 16;
3016 always_copy
= flags
& INFO_FL_ALWAYS_COPY
;
3019 if (copy_from_user(parg
, (void __user
*)arg
, n
))
3022 /* zero out anything we don't copy from userspace */
3024 memset((u8
*)parg
+ n
, 0, ioc_size
- n
);
3026 /* read-only ioctl */
3027 memset(parg
, 0, ioc_size
);
3031 err
= check_array_args(cmd
, parg
, &array_size
, &user_ptr
, &kernel_ptr
);
3034 has_array_args
= err
;
3036 if (has_array_args
) {
3038 * When adding new types of array args, make sure that the
3039 * parent argument to ioctl (which contains the pointer to the
3040 * array) fits into sbuf (so that mbuf will still remain
3041 * unused up to here).
3043 mbuf
= kvmalloc(array_size
, GFP_KERNEL
);
3046 goto out_array_args
;
3048 if (copy_from_user(mbuf
, user_ptr
, array_size
))
3049 goto out_array_args
;
3054 err
= func(file
, cmd
, parg
);
3055 if (err
== -ENOTTY
|| err
== -ENOIOCTLCMD
) {
3061 if (cmd
== VIDIOC_DQBUF
)
3062 trace_v4l2_dqbuf(video_devdata(file
)->minor
, parg
);
3063 else if (cmd
== VIDIOC_QBUF
)
3064 trace_v4l2_qbuf(video_devdata(file
)->minor
, parg
);
3067 if (has_array_args
) {
3068 *kernel_ptr
= (void __force
*)user_ptr
;
3069 if (copy_to_user(user_ptr
, mbuf
, array_size
))
3071 goto out_array_args
;
3074 * Some ioctls can return an error, but still have valid
3075 * results that must be returned.
3077 if (err
< 0 && !always_copy
)
3081 /* Copy results into user buffer */
3082 switch (_IOC_DIR(cmd
)) {
3084 case (_IOC_WRITE
| _IOC_READ
):
3085 if (copy_to_user((void __user
*)arg
, parg
, ioc_size
))
3095 long video_ioctl2(struct file
*file
,
3096 unsigned int cmd
, unsigned long arg
)
3098 return video_usercopy(file
, cmd
, arg
, __video_do_ioctl
);
3100 EXPORT_SYMBOL(video_ioctl2
);