1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Video capture interface for Linux version 2
5 * A generic framework to process V4L2 ioctl commands.
7 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
8 * Mauro Carvalho Chehab <mchehab@kernel.org> (version 2)
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/version.h>
18 #include <linux/videodev2.h>
20 #include <media/v4l2-common.h>
21 #include <media/v4l2-ioctl.h>
22 #include <media/v4l2-ctrls.h>
23 #include <media/v4l2-fh.h>
24 #include <media/v4l2-event.h>
25 #include <media/v4l2-device.h>
26 #include <media/videobuf2-v4l2.h>
27 #include <media/v4l2-mc.h>
28 #include <media/v4l2-mem2mem.h>
30 #include <trace/events/v4l2.h>
32 /* Zero out the end of the struct pointed to by p. Everything after, but
33 * not including, the specified field is cleared. */
34 #define CLEAR_AFTER_FIELD(p, field) \
35 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
36 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
38 #define is_valid_ioctl(vfd, cmd) test_bit(_IOC_NR(cmd), (vfd)->valid_ioctls)
45 static const struct std_descr standards
[] = {
46 { V4L2_STD_NTSC
, "NTSC" },
47 { V4L2_STD_NTSC_M
, "NTSC-M" },
48 { V4L2_STD_NTSC_M_JP
, "NTSC-M-JP" },
49 { V4L2_STD_NTSC_M_KR
, "NTSC-M-KR" },
50 { V4L2_STD_NTSC_443
, "NTSC-443" },
51 { V4L2_STD_PAL
, "PAL" },
52 { V4L2_STD_PAL_BG
, "PAL-BG" },
53 { V4L2_STD_PAL_B
, "PAL-B" },
54 { V4L2_STD_PAL_B1
, "PAL-B1" },
55 { V4L2_STD_PAL_G
, "PAL-G" },
56 { V4L2_STD_PAL_H
, "PAL-H" },
57 { V4L2_STD_PAL_I
, "PAL-I" },
58 { V4L2_STD_PAL_DK
, "PAL-DK" },
59 { V4L2_STD_PAL_D
, "PAL-D" },
60 { V4L2_STD_PAL_D1
, "PAL-D1" },
61 { V4L2_STD_PAL_K
, "PAL-K" },
62 { V4L2_STD_PAL_M
, "PAL-M" },
63 { V4L2_STD_PAL_N
, "PAL-N" },
64 { V4L2_STD_PAL_Nc
, "PAL-Nc" },
65 { V4L2_STD_PAL_60
, "PAL-60" },
66 { V4L2_STD_SECAM
, "SECAM" },
67 { V4L2_STD_SECAM_B
, "SECAM-B" },
68 { V4L2_STD_SECAM_G
, "SECAM-G" },
69 { V4L2_STD_SECAM_H
, "SECAM-H" },
70 { V4L2_STD_SECAM_DK
, "SECAM-DK" },
71 { V4L2_STD_SECAM_D
, "SECAM-D" },
72 { V4L2_STD_SECAM_K
, "SECAM-K" },
73 { V4L2_STD_SECAM_K1
, "SECAM-K1" },
74 { V4L2_STD_SECAM_L
, "SECAM-L" },
75 { V4L2_STD_SECAM_LC
, "SECAM-Lc" },
79 /* video4linux standard ID conversion to standard name
81 const char *v4l2_norm_to_name(v4l2_std_id id
)
86 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
87 64 bit comparisons. So, on that architecture, with some gcc
88 variants, compilation fails. Currently, the max value is 30bit wide.
92 for (i
= 0; standards
[i
].std
; i
++)
93 if (myid
== standards
[i
].std
)
95 return standards
[i
].descr
;
97 EXPORT_SYMBOL(v4l2_norm_to_name
);
99 /* Returns frame period for the given standard */
100 void v4l2_video_std_frame_period(int id
, struct v4l2_fract
*frameperiod
)
102 if (id
& V4L2_STD_525_60
) {
103 frameperiod
->numerator
= 1001;
104 frameperiod
->denominator
= 30000;
106 frameperiod
->numerator
= 1;
107 frameperiod
->denominator
= 25;
110 EXPORT_SYMBOL(v4l2_video_std_frame_period
);
112 /* Fill in the fields of a v4l2_standard structure according to the
113 'id' and 'transmission' parameters. Returns negative on error. */
114 int v4l2_video_std_construct(struct v4l2_standard
*vs
,
115 int id
, const char *name
)
118 v4l2_video_std_frame_period(id
, &vs
->frameperiod
);
119 vs
->framelines
= (id
& V4L2_STD_525_60
) ? 525 : 625;
120 strscpy(vs
->name
, name
, sizeof(vs
->name
));
123 EXPORT_SYMBOL(v4l2_video_std_construct
);
125 /* Fill in the fields of a v4l2_standard structure according to the
126 * 'id' and 'vs->index' parameters. Returns negative on error. */
127 int v4l_video_std_enumstd(struct v4l2_standard
*vs
, v4l2_std_id id
)
129 v4l2_std_id curr_id
= 0;
130 unsigned int index
= vs
->index
, i
, j
= 0;
131 const char *descr
= "";
133 /* Return -ENODATA if the id for the current input
134 or output is 0, meaning that it doesn't support this API. */
138 /* Return norm array in a canonical way */
139 for (i
= 0; i
<= index
&& id
; i
++) {
140 /* last std value in the standards array is 0, so this
141 while always ends there since (id & 0) == 0. */
142 while ((id
& standards
[j
].std
) != standards
[j
].std
)
144 curr_id
= standards
[j
].std
;
145 descr
= standards
[j
].descr
;
149 if (curr_id
!= V4L2_STD_PAL
&&
150 curr_id
!= V4L2_STD_SECAM
&&
151 curr_id
!= V4L2_STD_NTSC
)
157 v4l2_video_std_construct(vs
, curr_id
, descr
);
161 /* ----------------------------------------------------------------- */
162 /* some arrays for pretty-printing debug messages of enum types */
164 const char *v4l2_field_names
[] = {
165 [V4L2_FIELD_ANY
] = "any",
166 [V4L2_FIELD_NONE
] = "none",
167 [V4L2_FIELD_TOP
] = "top",
168 [V4L2_FIELD_BOTTOM
] = "bottom",
169 [V4L2_FIELD_INTERLACED
] = "interlaced",
170 [V4L2_FIELD_SEQ_TB
] = "seq-tb",
171 [V4L2_FIELD_SEQ_BT
] = "seq-bt",
172 [V4L2_FIELD_ALTERNATE
] = "alternate",
173 [V4L2_FIELD_INTERLACED_TB
] = "interlaced-tb",
174 [V4L2_FIELD_INTERLACED_BT
] = "interlaced-bt",
176 EXPORT_SYMBOL(v4l2_field_names
);
178 const char *v4l2_type_names
[] = {
180 [V4L2_BUF_TYPE_VIDEO_CAPTURE
] = "vid-cap",
181 [V4L2_BUF_TYPE_VIDEO_OVERLAY
] = "vid-overlay",
182 [V4L2_BUF_TYPE_VIDEO_OUTPUT
] = "vid-out",
183 [V4L2_BUF_TYPE_VBI_CAPTURE
] = "vbi-cap",
184 [V4L2_BUF_TYPE_VBI_OUTPUT
] = "vbi-out",
185 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
] = "sliced-vbi-cap",
186 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
] = "sliced-vbi-out",
187 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
] = "vid-out-overlay",
188 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
] = "vid-cap-mplane",
189 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
] = "vid-out-mplane",
190 [V4L2_BUF_TYPE_SDR_CAPTURE
] = "sdr-cap",
191 [V4L2_BUF_TYPE_SDR_OUTPUT
] = "sdr-out",
192 [V4L2_BUF_TYPE_META_CAPTURE
] = "meta-cap",
193 [V4L2_BUF_TYPE_META_OUTPUT
] = "meta-out",
195 EXPORT_SYMBOL(v4l2_type_names
);
197 static const char *v4l2_memory_names
[] = {
198 [V4L2_MEMORY_MMAP
] = "mmap",
199 [V4L2_MEMORY_USERPTR
] = "userptr",
200 [V4L2_MEMORY_OVERLAY
] = "overlay",
201 [V4L2_MEMORY_DMABUF
] = "dmabuf",
204 #define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown")
206 /* ------------------------------------------------------------------ */
207 /* debug help functions */
209 static void v4l_print_querycap(const void *arg
, bool write_only
)
211 const struct v4l2_capability
*p
= arg
;
213 pr_cont("driver=%.*s, card=%.*s, bus=%.*s, version=0x%08x, capabilities=0x%08x, device_caps=0x%08x\n",
214 (int)sizeof(p
->driver
), p
->driver
,
215 (int)sizeof(p
->card
), p
->card
,
216 (int)sizeof(p
->bus_info
), p
->bus_info
,
217 p
->version
, p
->capabilities
, p
->device_caps
);
220 static void v4l_print_enuminput(const void *arg
, bool write_only
)
222 const struct v4l2_input
*p
= arg
;
224 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, tuner=%u, std=0x%08Lx, status=0x%x, capabilities=0x%x\n",
225 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->type
, p
->audioset
,
226 p
->tuner
, (unsigned long long)p
->std
, p
->status
,
230 static void v4l_print_enumoutput(const void *arg
, bool write_only
)
232 const struct v4l2_output
*p
= arg
;
234 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, modulator=%u, std=0x%08Lx, capabilities=0x%x\n",
235 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->type
, p
->audioset
,
236 p
->modulator
, (unsigned long long)p
->std
, p
->capabilities
);
239 static void v4l_print_audio(const void *arg
, bool write_only
)
241 const struct v4l2_audio
*p
= arg
;
244 pr_cont("index=%u, mode=0x%x\n", p
->index
, p
->mode
);
246 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
247 p
->index
, (int)sizeof(p
->name
), p
->name
,
248 p
->capability
, p
->mode
);
251 static void v4l_print_audioout(const void *arg
, bool write_only
)
253 const struct v4l2_audioout
*p
= arg
;
256 pr_cont("index=%u\n", p
->index
);
258 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
259 p
->index
, (int)sizeof(p
->name
), p
->name
,
260 p
->capability
, p
->mode
);
263 static void v4l_print_fmtdesc(const void *arg
, bool write_only
)
265 const struct v4l2_fmtdesc
*p
= arg
;
267 pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%.*s'\n",
268 p
->index
, prt_names(p
->type
, v4l2_type_names
),
269 p
->flags
, (p
->pixelformat
& 0xff),
270 (p
->pixelformat
>> 8) & 0xff,
271 (p
->pixelformat
>> 16) & 0xff,
272 (p
->pixelformat
>> 24) & 0xff,
273 (int)sizeof(p
->description
), p
->description
);
276 static void v4l_print_format(const void *arg
, bool write_only
)
278 const struct v4l2_format
*p
= arg
;
279 const struct v4l2_pix_format
*pix
;
280 const struct v4l2_pix_format_mplane
*mp
;
281 const struct v4l2_vbi_format
*vbi
;
282 const struct v4l2_sliced_vbi_format
*sliced
;
283 const struct v4l2_window
*win
;
284 const struct v4l2_sdr_format
*sdr
;
285 const struct v4l2_meta_format
*meta
;
289 pr_cont("type=%s", prt_names(p
->type
, v4l2_type_names
));
291 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
292 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
294 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",
295 pix
->width
, pix
->height
,
296 (pix
->pixelformat
& 0xff),
297 (pix
->pixelformat
>> 8) & 0xff,
298 (pix
->pixelformat
>> 16) & 0xff,
299 (pix
->pixelformat
>> 24) & 0xff,
300 prt_names(pix
->field
, v4l2_field_names
),
301 pix
->bytesperline
, pix
->sizeimage
,
302 pix
->colorspace
, pix
->flags
, pix
->ycbcr_enc
,
303 pix
->quantization
, pix
->xfer_func
);
305 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
306 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
308 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",
309 mp
->width
, mp
->height
,
310 (mp
->pixelformat
& 0xff),
311 (mp
->pixelformat
>> 8) & 0xff,
312 (mp
->pixelformat
>> 16) & 0xff,
313 (mp
->pixelformat
>> 24) & 0xff,
314 prt_names(mp
->field
, v4l2_field_names
),
315 mp
->colorspace
, mp
->num_planes
, mp
->flags
,
316 mp
->ycbcr_enc
, mp
->quantization
, mp
->xfer_func
);
317 planes
= min_t(u32
, mp
->num_planes
, VIDEO_MAX_PLANES
);
318 for (i
= 0; i
< planes
; i
++)
319 printk(KERN_DEBUG
"plane %u: bytesperline=%u sizeimage=%u\n", i
,
320 mp
->plane_fmt
[i
].bytesperline
,
321 mp
->plane_fmt
[i
].sizeimage
);
323 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
324 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
326 /* Note: we can't print the clip list here since the clips
327 * pointer is a userspace pointer, not a kernelspace
329 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",
330 win
->w
.width
, win
->w
.height
, win
->w
.left
, win
->w
.top
,
331 prt_names(win
->field
, v4l2_field_names
),
332 win
->chromakey
, win
->clipcount
, win
->clips
,
333 win
->bitmap
, win
->global_alpha
);
335 case V4L2_BUF_TYPE_VBI_CAPTURE
:
336 case V4L2_BUF_TYPE_VBI_OUTPUT
:
338 pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, sample_format=%c%c%c%c, start=%u,%u, count=%u,%u\n",
339 vbi
->sampling_rate
, vbi
->offset
,
340 vbi
->samples_per_line
,
341 (vbi
->sample_format
& 0xff),
342 (vbi
->sample_format
>> 8) & 0xff,
343 (vbi
->sample_format
>> 16) & 0xff,
344 (vbi
->sample_format
>> 24) & 0xff,
345 vbi
->start
[0], vbi
->start
[1],
346 vbi
->count
[0], vbi
->count
[1]);
348 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
349 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
350 sliced
= &p
->fmt
.sliced
;
351 pr_cont(", service_set=0x%08x, io_size=%d\n",
352 sliced
->service_set
, sliced
->io_size
);
353 for (i
= 0; i
< 24; i
++)
354 printk(KERN_DEBUG
"line[%02u]=0x%04x, 0x%04x\n", i
,
355 sliced
->service_lines
[0][i
],
356 sliced
->service_lines
[1][i
]);
358 case V4L2_BUF_TYPE_SDR_CAPTURE
:
359 case V4L2_BUF_TYPE_SDR_OUTPUT
:
361 pr_cont(", pixelformat=%c%c%c%c\n",
362 (sdr
->pixelformat
>> 0) & 0xff,
363 (sdr
->pixelformat
>> 8) & 0xff,
364 (sdr
->pixelformat
>> 16) & 0xff,
365 (sdr
->pixelformat
>> 24) & 0xff);
367 case V4L2_BUF_TYPE_META_CAPTURE
:
368 case V4L2_BUF_TYPE_META_OUTPUT
:
370 pr_cont(", dataformat=%c%c%c%c, buffersize=%u\n",
371 (meta
->dataformat
>> 0) & 0xff,
372 (meta
->dataformat
>> 8) & 0xff,
373 (meta
->dataformat
>> 16) & 0xff,
374 (meta
->dataformat
>> 24) & 0xff,
380 static void v4l_print_framebuffer(const void *arg
, bool write_only
)
382 const struct v4l2_framebuffer
*p
= arg
;
384 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",
385 p
->capability
, p
->flags
, p
->base
,
386 p
->fmt
.width
, p
->fmt
.height
,
387 (p
->fmt
.pixelformat
& 0xff),
388 (p
->fmt
.pixelformat
>> 8) & 0xff,
389 (p
->fmt
.pixelformat
>> 16) & 0xff,
390 (p
->fmt
.pixelformat
>> 24) & 0xff,
391 p
->fmt
.bytesperline
, p
->fmt
.sizeimage
,
395 static void v4l_print_buftype(const void *arg
, bool write_only
)
397 pr_cont("type=%s\n", prt_names(*(u32
*)arg
, v4l2_type_names
));
400 static void v4l_print_modulator(const void *arg
, bool write_only
)
402 const struct v4l2_modulator
*p
= arg
;
405 pr_cont("index=%u, txsubchans=0x%x\n", p
->index
, p
->txsubchans
);
407 pr_cont("index=%u, name=%.*s, capability=0x%x, rangelow=%u, rangehigh=%u, txsubchans=0x%x\n",
408 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->capability
,
409 p
->rangelow
, p
->rangehigh
, p
->txsubchans
);
412 static void v4l_print_tuner(const void *arg
, bool write_only
)
414 const struct v4l2_tuner
*p
= arg
;
417 pr_cont("index=%u, audmode=%u\n", p
->index
, p
->audmode
);
419 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",
420 p
->index
, (int)sizeof(p
->name
), p
->name
, p
->type
,
421 p
->capability
, p
->rangelow
,
422 p
->rangehigh
, p
->signal
, p
->afc
,
423 p
->rxsubchans
, p
->audmode
);
426 static void v4l_print_frequency(const void *arg
, bool write_only
)
428 const struct v4l2_frequency
*p
= arg
;
430 pr_cont("tuner=%u, type=%u, frequency=%u\n",
431 p
->tuner
, p
->type
, p
->frequency
);
434 static void v4l_print_standard(const void *arg
, bool write_only
)
436 const struct v4l2_standard
*p
= arg
;
438 pr_cont("index=%u, id=0x%Lx, name=%.*s, fps=%u/%u, framelines=%u\n",
440 (unsigned long long)p
->id
, (int)sizeof(p
->name
), p
->name
,
441 p
->frameperiod
.numerator
,
442 p
->frameperiod
.denominator
,
446 static void v4l_print_std(const void *arg
, bool write_only
)
448 pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg
);
451 static void v4l_print_hw_freq_seek(const void *arg
, bool write_only
)
453 const struct v4l2_hw_freq_seek
*p
= arg
;
455 pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u, rangelow=%u, rangehigh=%u\n",
456 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
, p
->spacing
,
457 p
->rangelow
, p
->rangehigh
);
460 static void v4l_print_requestbuffers(const void *arg
, bool write_only
)
462 const struct v4l2_requestbuffers
*p
= arg
;
464 pr_cont("count=%d, type=%s, memory=%s\n",
466 prt_names(p
->type
, v4l2_type_names
),
467 prt_names(p
->memory
, v4l2_memory_names
));
470 static void v4l_print_buffer(const void *arg
, bool write_only
)
472 const struct v4l2_buffer
*p
= arg
;
473 const struct v4l2_timecode
*tc
= &p
->timecode
;
474 const struct v4l2_plane
*plane
;
477 pr_cont("%02d:%02d:%02d.%09ld index=%d, type=%s, request_fd=%d, flags=0x%08x, field=%s, sequence=%d, memory=%s",
478 (int)p
->timestamp
.tv_sec
/ 3600,
479 ((int)p
->timestamp
.tv_sec
/ 60) % 60,
480 ((int)p
->timestamp
.tv_sec
% 60),
481 (long)p
->timestamp
.tv_usec
,
483 prt_names(p
->type
, v4l2_type_names
), p
->request_fd
,
484 p
->flags
, prt_names(p
->field
, v4l2_field_names
),
485 p
->sequence
, prt_names(p
->memory
, v4l2_memory_names
));
487 if (V4L2_TYPE_IS_MULTIPLANAR(p
->type
) && p
->m
.planes
) {
489 for (i
= 0; i
< p
->length
; ++i
) {
490 plane
= &p
->m
.planes
[i
];
492 "plane %d: bytesused=%d, data_offset=0x%08x, offset/userptr=0x%lx, length=%d\n",
493 i
, plane
->bytesused
, plane
->data_offset
,
494 plane
->m
.userptr
, plane
->length
);
497 pr_cont(", bytesused=%d, offset/userptr=0x%lx, length=%d\n",
498 p
->bytesused
, p
->m
.userptr
, p
->length
);
501 printk(KERN_DEBUG
"timecode=%02d:%02d:%02d type=%d, flags=0x%08x, frames=%d, userbits=0x%08x\n",
502 tc
->hours
, tc
->minutes
, tc
->seconds
,
503 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
506 static void v4l_print_exportbuffer(const void *arg
, bool write_only
)
508 const struct v4l2_exportbuffer
*p
= arg
;
510 pr_cont("fd=%d, type=%s, index=%u, plane=%u, flags=0x%08x\n",
511 p
->fd
, prt_names(p
->type
, v4l2_type_names
),
512 p
->index
, p
->plane
, p
->flags
);
515 static void v4l_print_create_buffers(const void *arg
, bool write_only
)
517 const struct v4l2_create_buffers
*p
= arg
;
519 pr_cont("index=%d, count=%d, memory=%s, ",
521 prt_names(p
->memory
, v4l2_memory_names
));
522 v4l_print_format(&p
->format
, write_only
);
525 static void v4l_print_streamparm(const void *arg
, bool write_only
)
527 const struct v4l2_streamparm
*p
= arg
;
529 pr_cont("type=%s", prt_names(p
->type
, v4l2_type_names
));
531 if (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
||
532 p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
533 const struct v4l2_captureparm
*c
= &p
->parm
.capture
;
535 pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, extendedmode=%d, readbuffers=%d\n",
536 c
->capability
, c
->capturemode
,
537 c
->timeperframe
.numerator
, c
->timeperframe
.denominator
,
538 c
->extendedmode
, c
->readbuffers
);
539 } else if (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
||
540 p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
541 const struct v4l2_outputparm
*c
= &p
->parm
.output
;
543 pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, extendedmode=%d, writebuffers=%d\n",
544 c
->capability
, c
->outputmode
,
545 c
->timeperframe
.numerator
, c
->timeperframe
.denominator
,
546 c
->extendedmode
, c
->writebuffers
);
552 static void v4l_print_queryctrl(const void *arg
, bool write_only
)
554 const struct v4l2_queryctrl
*p
= arg
;
556 pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%d/%d, step=%d, default=%d, flags=0x%08x\n",
557 p
->id
, p
->type
, (int)sizeof(p
->name
), p
->name
,
558 p
->minimum
, p
->maximum
,
559 p
->step
, p
->default_value
, p
->flags
);
562 static void v4l_print_query_ext_ctrl(const void *arg
, bool write_only
)
564 const struct v4l2_query_ext_ctrl
*p
= arg
;
566 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",
567 p
->id
, p
->type
, (int)sizeof(p
->name
), p
->name
,
568 p
->minimum
, p
->maximum
,
569 p
->step
, p
->default_value
, p
->flags
,
570 p
->elem_size
, p
->elems
, p
->nr_of_dims
,
571 p
->dims
[0], p
->dims
[1], p
->dims
[2], p
->dims
[3]);
574 static void v4l_print_querymenu(const void *arg
, bool write_only
)
576 const struct v4l2_querymenu
*p
= arg
;
578 pr_cont("id=0x%x, index=%d\n", p
->id
, p
->index
);
581 static void v4l_print_control(const void *arg
, bool write_only
)
583 const struct v4l2_control
*p
= arg
;
585 pr_cont("id=0x%x, value=%d\n", p
->id
, p
->value
);
588 static void v4l_print_ext_controls(const void *arg
, bool write_only
)
590 const struct v4l2_ext_controls
*p
= arg
;
593 pr_cont("which=0x%x, count=%d, error_idx=%d, request_fd=%d",
594 p
->which
, p
->count
, p
->error_idx
, p
->request_fd
);
595 for (i
= 0; i
< p
->count
; i
++) {
596 if (!p
->controls
[i
].size
)
597 pr_cont(", id/val=0x%x/0x%x",
598 p
->controls
[i
].id
, p
->controls
[i
].value
);
600 pr_cont(", id/size=0x%x/%u",
601 p
->controls
[i
].id
, p
->controls
[i
].size
);
606 static void v4l_print_cropcap(const void *arg
, bool write_only
)
608 const struct v4l2_cropcap
*p
= arg
;
610 pr_cont("type=%s, bounds wxh=%dx%d, x,y=%d,%d, defrect wxh=%dx%d, x,y=%d,%d, pixelaspect %d/%d\n",
611 prt_names(p
->type
, v4l2_type_names
),
612 p
->bounds
.width
, p
->bounds
.height
,
613 p
->bounds
.left
, p
->bounds
.top
,
614 p
->defrect
.width
, p
->defrect
.height
,
615 p
->defrect
.left
, p
->defrect
.top
,
616 p
->pixelaspect
.numerator
, p
->pixelaspect
.denominator
);
619 static void v4l_print_crop(const void *arg
, bool write_only
)
621 const struct v4l2_crop
*p
= arg
;
623 pr_cont("type=%s, wxh=%dx%d, x,y=%d,%d\n",
624 prt_names(p
->type
, v4l2_type_names
),
625 p
->c
.width
, p
->c
.height
,
626 p
->c
.left
, p
->c
.top
);
629 static void v4l_print_selection(const void *arg
, bool write_only
)
631 const struct v4l2_selection
*p
= arg
;
633 pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
634 prt_names(p
->type
, v4l2_type_names
),
636 p
->r
.width
, p
->r
.height
, p
->r
.left
, p
->r
.top
);
639 static void v4l_print_jpegcompression(const void *arg
, bool write_only
)
641 const struct v4l2_jpegcompression
*p
= arg
;
643 pr_cont("quality=%d, APPn=%d, APP_len=%d, COM_len=%d, jpeg_markers=0x%x\n",
644 p
->quality
, p
->APPn
, p
->APP_len
,
645 p
->COM_len
, p
->jpeg_markers
);
648 static void v4l_print_enc_idx(const void *arg
, bool write_only
)
650 const struct v4l2_enc_idx
*p
= arg
;
652 pr_cont("entries=%d, entries_cap=%d\n",
653 p
->entries
, p
->entries_cap
);
656 static void v4l_print_encoder_cmd(const void *arg
, bool write_only
)
658 const struct v4l2_encoder_cmd
*p
= arg
;
660 pr_cont("cmd=%d, flags=0x%x\n",
664 static void v4l_print_decoder_cmd(const void *arg
, bool write_only
)
666 const struct v4l2_decoder_cmd
*p
= arg
;
668 pr_cont("cmd=%d, flags=0x%x\n", p
->cmd
, p
->flags
);
670 if (p
->cmd
== V4L2_DEC_CMD_START
)
671 pr_info("speed=%d, format=%u\n",
672 p
->start
.speed
, p
->start
.format
);
673 else if (p
->cmd
== V4L2_DEC_CMD_STOP
)
674 pr_info("pts=%llu\n", p
->stop
.pts
);
677 static void v4l_print_dbg_chip_info(const void *arg
, bool write_only
)
679 const struct v4l2_dbg_chip_info
*p
= arg
;
681 pr_cont("type=%u, ", p
->match
.type
);
682 if (p
->match
.type
== V4L2_CHIP_MATCH_I2C_DRIVER
)
683 pr_cont("name=%.*s, ",
684 (int)sizeof(p
->match
.name
), p
->match
.name
);
686 pr_cont("addr=%u, ", p
->match
.addr
);
687 pr_cont("name=%.*s\n", (int)sizeof(p
->name
), p
->name
);
690 static void v4l_print_dbg_register(const void *arg
, bool write_only
)
692 const struct v4l2_dbg_register
*p
= arg
;
694 pr_cont("type=%u, ", p
->match
.type
);
695 if (p
->match
.type
== V4L2_CHIP_MATCH_I2C_DRIVER
)
696 pr_cont("name=%.*s, ",
697 (int)sizeof(p
->match
.name
), p
->match
.name
);
699 pr_cont("addr=%u, ", p
->match
.addr
);
700 pr_cont("reg=0x%llx, val=0x%llx\n",
704 static void v4l_print_dv_timings(const void *arg
, bool write_only
)
706 const struct v4l2_dv_timings
*p
= arg
;
709 case V4L2_DV_BT_656_1120
:
710 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",
711 p
->bt
.interlaced
, p
->bt
.pixelclock
,
712 p
->bt
.width
, p
->bt
.height
,
713 p
->bt
.polarities
, p
->bt
.hfrontporch
,
714 p
->bt
.hsync
, p
->bt
.hbackporch
,
715 p
->bt
.vfrontporch
, p
->bt
.vsync
,
716 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
717 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
,
718 p
->bt
.standards
, p
->bt
.flags
);
721 pr_cont("type=%d\n", p
->type
);
726 static void v4l_print_enum_dv_timings(const void *arg
, bool write_only
)
728 const struct v4l2_enum_dv_timings
*p
= arg
;
730 pr_cont("index=%u, ", p
->index
);
731 v4l_print_dv_timings(&p
->timings
, write_only
);
734 static void v4l_print_dv_timings_cap(const void *arg
, bool write_only
)
736 const struct v4l2_dv_timings_cap
*p
= arg
;
739 case V4L2_DV_BT_656_1120
:
740 pr_cont("type=bt-656/1120, width=%u-%u, height=%u-%u, pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n",
741 p
->bt
.min_width
, p
->bt
.max_width
,
742 p
->bt
.min_height
, p
->bt
.max_height
,
743 p
->bt
.min_pixelclock
, p
->bt
.max_pixelclock
,
744 p
->bt
.standards
, p
->bt
.capabilities
);
747 pr_cont("type=%u\n", p
->type
);
752 static void v4l_print_frmsizeenum(const void *arg
, bool write_only
)
754 const struct v4l2_frmsizeenum
*p
= arg
;
756 pr_cont("index=%u, pixelformat=%c%c%c%c, type=%u",
758 (p
->pixel_format
& 0xff),
759 (p
->pixel_format
>> 8) & 0xff,
760 (p
->pixel_format
>> 16) & 0xff,
761 (p
->pixel_format
>> 24) & 0xff,
764 case V4L2_FRMSIZE_TYPE_DISCRETE
:
765 pr_cont(", wxh=%ux%u\n",
766 p
->discrete
.width
, p
->discrete
.height
);
768 case V4L2_FRMSIZE_TYPE_STEPWISE
:
769 pr_cont(", min=%ux%u, max=%ux%u, step=%ux%u\n",
770 p
->stepwise
.min_width
,
771 p
->stepwise
.min_height
,
772 p
->stepwise
.max_width
,
773 p
->stepwise
.max_height
,
774 p
->stepwise
.step_width
,
775 p
->stepwise
.step_height
);
777 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
785 static void v4l_print_frmivalenum(const void *arg
, bool write_only
)
787 const struct v4l2_frmivalenum
*p
= arg
;
789 pr_cont("index=%u, pixelformat=%c%c%c%c, wxh=%ux%u, type=%u",
791 (p
->pixel_format
& 0xff),
792 (p
->pixel_format
>> 8) & 0xff,
793 (p
->pixel_format
>> 16) & 0xff,
794 (p
->pixel_format
>> 24) & 0xff,
795 p
->width
, p
->height
, p
->type
);
797 case V4L2_FRMIVAL_TYPE_DISCRETE
:
798 pr_cont(", fps=%d/%d\n",
799 p
->discrete
.numerator
,
800 p
->discrete
.denominator
);
802 case V4L2_FRMIVAL_TYPE_STEPWISE
:
803 pr_cont(", min=%d/%d, max=%d/%d, step=%d/%d\n",
804 p
->stepwise
.min
.numerator
,
805 p
->stepwise
.min
.denominator
,
806 p
->stepwise
.max
.numerator
,
807 p
->stepwise
.max
.denominator
,
808 p
->stepwise
.step
.numerator
,
809 p
->stepwise
.step
.denominator
);
811 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
819 static void v4l_print_event(const void *arg
, bool write_only
)
821 const struct v4l2_event
*p
= arg
;
822 const struct v4l2_event_ctrl
*c
;
824 pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, timestamp=%llu.%9.9llu\n",
825 p
->type
, p
->pending
, p
->sequence
, p
->id
,
826 p
->timestamp
.tv_sec
, p
->timestamp
.tv_nsec
);
828 case V4L2_EVENT_VSYNC
:
829 printk(KERN_DEBUG
"field=%s\n",
830 prt_names(p
->u
.vsync
.field
, v4l2_field_names
));
832 case V4L2_EVENT_CTRL
:
834 printk(KERN_DEBUG
"changes=0x%x, type=%u, ",
835 c
->changes
, c
->type
);
836 if (c
->type
== V4L2_CTRL_TYPE_INTEGER64
)
837 pr_cont("value64=%lld, ", c
->value64
);
839 pr_cont("value=%d, ", c
->value
);
840 pr_cont("flags=0x%x, minimum=%d, maximum=%d, step=%d, default_value=%d\n",
841 c
->flags
, c
->minimum
, c
->maximum
,
842 c
->step
, c
->default_value
);
844 case V4L2_EVENT_FRAME_SYNC
:
845 pr_cont("frame_sequence=%u\n",
846 p
->u
.frame_sync
.frame_sequence
);
851 static void v4l_print_event_subscription(const void *arg
, bool write_only
)
853 const struct v4l2_event_subscription
*p
= arg
;
855 pr_cont("type=0x%x, id=0x%x, flags=0x%x\n",
856 p
->type
, p
->id
, p
->flags
);
859 static void v4l_print_sliced_vbi_cap(const void *arg
, bool write_only
)
861 const struct v4l2_sliced_vbi_cap
*p
= arg
;
864 pr_cont("type=%s, service_set=0x%08x\n",
865 prt_names(p
->type
, v4l2_type_names
), p
->service_set
);
866 for (i
= 0; i
< 24; i
++)
867 printk(KERN_DEBUG
"line[%02u]=0x%04x, 0x%04x\n", i
,
868 p
->service_lines
[0][i
],
869 p
->service_lines
[1][i
]);
872 static void v4l_print_freq_band(const void *arg
, bool write_only
)
874 const struct v4l2_frequency_band
*p
= arg
;
876 pr_cont("tuner=%u, type=%u, index=%u, capability=0x%x, rangelow=%u, rangehigh=%u, modulation=0x%x\n",
877 p
->tuner
, p
->type
, p
->index
,
878 p
->capability
, p
->rangelow
,
879 p
->rangehigh
, p
->modulation
);
882 static void v4l_print_edid(const void *arg
, bool write_only
)
884 const struct v4l2_edid
*p
= arg
;
886 pr_cont("pad=%u, start_block=%u, blocks=%u\n",
887 p
->pad
, p
->start_block
, p
->blocks
);
890 static void v4l_print_u32(const void *arg
, bool write_only
)
892 pr_cont("value=%u\n", *(const u32
*)arg
);
895 static void v4l_print_newline(const void *arg
, bool write_only
)
900 static void v4l_print_default(const void *arg
, bool write_only
)
902 pr_cont("driver-specific ioctl\n");
905 static int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
909 /* zero the reserved fields */
911 for (i
= 0; i
< c
->count
; i
++)
912 c
->controls
[i
].reserved2
[0] = 0;
914 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
915 when using extended controls.
916 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
917 is it allowed for backwards compatibility.
919 if (!allow_priv
&& c
->which
== V4L2_CID_PRIVATE_BASE
)
923 /* Check that all controls are from the same control class. */
924 for (i
= 0; i
< c
->count
; i
++) {
925 if (V4L2_CTRL_ID2WHICH(c
->controls
[i
].id
) != c
->which
) {
933 static int check_fmt(struct file
*file
, enum v4l2_buf_type type
)
935 const u32 vid_caps
= V4L2_CAP_VIDEO_CAPTURE
|
936 V4L2_CAP_VIDEO_CAPTURE_MPLANE
|
937 V4L2_CAP_VIDEO_OUTPUT
|
938 V4L2_CAP_VIDEO_OUTPUT_MPLANE
|
939 V4L2_CAP_VIDEO_M2M
| V4L2_CAP_VIDEO_M2M_MPLANE
;
940 const u32 meta_caps
= V4L2_CAP_META_CAPTURE
|
941 V4L2_CAP_META_OUTPUT
;
942 struct video_device
*vfd
= video_devdata(file
);
943 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
944 bool is_vid
= vfd
->vfl_type
== VFL_TYPE_VIDEO
&&
945 (vfd
->device_caps
& vid_caps
);
946 bool is_vbi
= vfd
->vfl_type
== VFL_TYPE_VBI
;
947 bool is_sdr
= vfd
->vfl_type
== VFL_TYPE_SDR
;
948 bool is_tch
= vfd
->vfl_type
== VFL_TYPE_TOUCH
;
949 bool is_meta
= vfd
->vfl_type
== VFL_TYPE_VIDEO
&&
950 (vfd
->device_caps
& meta_caps
);
951 bool is_rx
= vfd
->vfl_dir
!= VFL_DIR_TX
;
952 bool is_tx
= vfd
->vfl_dir
!= VFL_DIR_RX
;
958 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
959 if ((is_vid
|| is_tch
) && is_rx
&&
960 (ops
->vidioc_g_fmt_vid_cap
|| ops
->vidioc_g_fmt_vid_cap_mplane
))
963 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
964 if ((is_vid
|| is_tch
) && is_rx
&& ops
->vidioc_g_fmt_vid_cap_mplane
)
967 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
968 if (is_vid
&& is_rx
&& ops
->vidioc_g_fmt_vid_overlay
)
971 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
972 if (is_vid
&& is_tx
&&
973 (ops
->vidioc_g_fmt_vid_out
|| ops
->vidioc_g_fmt_vid_out_mplane
))
976 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
977 if (is_vid
&& is_tx
&& ops
->vidioc_g_fmt_vid_out_mplane
)
980 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
981 if (is_vid
&& is_tx
&& ops
->vidioc_g_fmt_vid_out_overlay
)
984 case V4L2_BUF_TYPE_VBI_CAPTURE
:
985 if (is_vbi
&& is_rx
&& ops
->vidioc_g_fmt_vbi_cap
)
988 case V4L2_BUF_TYPE_VBI_OUTPUT
:
989 if (is_vbi
&& is_tx
&& ops
->vidioc_g_fmt_vbi_out
)
992 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
993 if (is_vbi
&& is_rx
&& ops
->vidioc_g_fmt_sliced_vbi_cap
)
996 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
997 if (is_vbi
&& is_tx
&& ops
->vidioc_g_fmt_sliced_vbi_out
)
1000 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1001 if (is_sdr
&& is_rx
&& ops
->vidioc_g_fmt_sdr_cap
)
1004 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1005 if (is_sdr
&& is_tx
&& ops
->vidioc_g_fmt_sdr_out
)
1008 case V4L2_BUF_TYPE_META_CAPTURE
:
1009 if (is_meta
&& is_rx
&& ops
->vidioc_g_fmt_meta_cap
)
1012 case V4L2_BUF_TYPE_META_OUTPUT
:
1013 if (is_meta
&& is_tx
&& ops
->vidioc_g_fmt_meta_out
)
1022 static void v4l_sanitize_format(struct v4l2_format
*fmt
)
1024 unsigned int offset
;
1026 /* Make sure num_planes is not bogus */
1027 if (fmt
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
1028 fmt
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
1029 fmt
->fmt
.pix_mp
.num_planes
= min_t(u32
, fmt
->fmt
.pix_mp
.num_planes
,
1033 * The v4l2_pix_format structure has been extended with fields that were
1034 * not previously required to be set to zero by applications. The priv
1035 * field, when set to a magic value, indicates the the extended fields
1036 * are valid. Otherwise they will contain undefined values. To simplify
1037 * the API towards drivers zero the extended fields and set the priv
1038 * field to the magic value when the extended pixel format structure
1039 * isn't used by applications.
1042 if (fmt
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
1043 fmt
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1046 if (fmt
->fmt
.pix
.priv
== V4L2_PIX_FMT_PRIV_MAGIC
)
1049 fmt
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1051 offset
= offsetof(struct v4l2_pix_format
, priv
)
1052 + sizeof(fmt
->fmt
.pix
.priv
);
1053 memset(((void *)&fmt
->fmt
.pix
) + offset
, 0,
1054 sizeof(fmt
->fmt
.pix
) - offset
);
1057 static int v4l_querycap(const struct v4l2_ioctl_ops
*ops
,
1058 struct file
*file
, void *fh
, void *arg
)
1060 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
1061 struct video_device
*vfd
= video_devdata(file
);
1064 cap
->version
= LINUX_VERSION_CODE
;
1065 cap
->device_caps
= vfd
->device_caps
;
1066 cap
->capabilities
= vfd
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
1068 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
1071 * Drivers must not change device_caps, so check for this and
1072 * warn if this happened.
1074 WARN_ON(cap
->device_caps
!= vfd
->device_caps
);
1076 * Check that capabilities is a superset of
1077 * vfd->device_caps | V4L2_CAP_DEVICE_CAPS
1079 WARN_ON((cap
->capabilities
&
1080 (vfd
->device_caps
| V4L2_CAP_DEVICE_CAPS
)) !=
1081 (vfd
->device_caps
| V4L2_CAP_DEVICE_CAPS
));
1082 cap
->capabilities
|= V4L2_CAP_EXT_PIX_FORMAT
;
1083 cap
->device_caps
|= V4L2_CAP_EXT_PIX_FORMAT
;
1088 static int v4l_s_input(const struct v4l2_ioctl_ops
*ops
,
1089 struct file
*file
, void *fh
, void *arg
)
1091 struct video_device
*vfd
= video_devdata(file
);
1094 ret
= v4l_enable_media_source(vfd
);
1097 return ops
->vidioc_s_input(file
, fh
, *(unsigned int *)arg
);
1100 static int v4l_s_output(const struct v4l2_ioctl_ops
*ops
,
1101 struct file
*file
, void *fh
, void *arg
)
1103 return ops
->vidioc_s_output(file
, fh
, *(unsigned int *)arg
);
1106 static int v4l_g_priority(const struct v4l2_ioctl_ops
*ops
,
1107 struct file
*file
, void *fh
, void *arg
)
1109 struct video_device
*vfd
;
1112 vfd
= video_devdata(file
);
1113 *p
= v4l2_prio_max(vfd
->prio
);
1117 static int v4l_s_priority(const struct v4l2_ioctl_ops
*ops
,
1118 struct file
*file
, void *fh
, void *arg
)
1120 struct video_device
*vfd
;
1121 struct v4l2_fh
*vfh
;
1124 vfd
= video_devdata(file
);
1125 if (!test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
))
1127 vfh
= file
->private_data
;
1128 return v4l2_prio_change(vfd
->prio
, &vfh
->prio
, *p
);
1131 static int v4l_enuminput(const struct v4l2_ioctl_ops
*ops
,
1132 struct file
*file
, void *fh
, void *arg
)
1134 struct video_device
*vfd
= video_devdata(file
);
1135 struct v4l2_input
*p
= arg
;
1138 * We set the flags for CAP_DV_TIMINGS &
1139 * CAP_STD here based on ioctl handler provided by the
1140 * driver. If the driver doesn't support these
1141 * for a specific input, it must override these flags.
1143 if (is_valid_ioctl(vfd
, VIDIOC_S_STD
))
1144 p
->capabilities
|= V4L2_IN_CAP_STD
;
1146 return ops
->vidioc_enum_input(file
, fh
, p
);
1149 static int v4l_enumoutput(const struct v4l2_ioctl_ops
*ops
,
1150 struct file
*file
, void *fh
, void *arg
)
1152 struct video_device
*vfd
= video_devdata(file
);
1153 struct v4l2_output
*p
= arg
;
1156 * We set the flags for CAP_DV_TIMINGS &
1157 * CAP_STD here based on ioctl handler provided by the
1158 * driver. If the driver doesn't support these
1159 * for a specific output, it must override these flags.
1161 if (is_valid_ioctl(vfd
, VIDIOC_S_STD
))
1162 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1164 return ops
->vidioc_enum_output(file
, fh
, p
);
1167 static void v4l_fill_fmtdesc(struct v4l2_fmtdesc
*fmt
)
1169 const unsigned sz
= sizeof(fmt
->description
);
1170 const char *descr
= NULL
;
1174 * We depart from the normal coding style here since the descriptions
1175 * should be aligned so it is easy to see which descriptions will be
1176 * longer than 31 characters (the max length for a description).
1177 * And frankly, this is easier to read anyway.
1179 * Note that gcc will use O(log N) comparisons to find the right case.
1181 switch (fmt
->pixelformat
) {
1182 /* Max description length mask: descr = "0123456789012345678901234567890" */
1183 case V4L2_PIX_FMT_RGB332
: descr
= "8-bit RGB 3-3-2"; break;
1184 case V4L2_PIX_FMT_RGB444
: descr
= "16-bit A/XRGB 4-4-4-4"; break;
1185 case V4L2_PIX_FMT_ARGB444
: descr
= "16-bit ARGB 4-4-4-4"; break;
1186 case V4L2_PIX_FMT_XRGB444
: descr
= "16-bit XRGB 4-4-4-4"; break;
1187 case V4L2_PIX_FMT_RGBA444
: descr
= "16-bit RGBA 4-4-4-4"; break;
1188 case V4L2_PIX_FMT_RGBX444
: descr
= "16-bit RGBX 4-4-4-4"; break;
1189 case V4L2_PIX_FMT_ABGR444
: descr
= "16-bit ABGR 4-4-4-4"; break;
1190 case V4L2_PIX_FMT_XBGR444
: descr
= "16-bit XBGR 4-4-4-4"; break;
1191 case V4L2_PIX_FMT_BGRA444
: descr
= "16-bit BGRA 4-4-4-4"; break;
1192 case V4L2_PIX_FMT_BGRX444
: descr
= "16-bit BGRX 4-4-4-4"; break;
1193 case V4L2_PIX_FMT_RGB555
: descr
= "16-bit A/XRGB 1-5-5-5"; break;
1194 case V4L2_PIX_FMT_ARGB555
: descr
= "16-bit ARGB 1-5-5-5"; break;
1195 case V4L2_PIX_FMT_XRGB555
: descr
= "16-bit XRGB 1-5-5-5"; break;
1196 case V4L2_PIX_FMT_ABGR555
: descr
= "16-bit ABGR 1-5-5-5"; break;
1197 case V4L2_PIX_FMT_XBGR555
: descr
= "16-bit XBGR 1-5-5-5"; break;
1198 case V4L2_PIX_FMT_RGBA555
: descr
= "16-bit RGBA 5-5-5-1"; break;
1199 case V4L2_PIX_FMT_RGBX555
: descr
= "16-bit RGBX 5-5-5-1"; break;
1200 case V4L2_PIX_FMT_BGRA555
: descr
= "16-bit BGRA 5-5-5-1"; break;
1201 case V4L2_PIX_FMT_BGRX555
: descr
= "16-bit BGRX 5-5-5-1"; break;
1202 case V4L2_PIX_FMT_RGB565
: descr
= "16-bit RGB 5-6-5"; break;
1203 case V4L2_PIX_FMT_RGB555X
: descr
= "16-bit A/XRGB 1-5-5-5 BE"; break;
1204 case V4L2_PIX_FMT_ARGB555X
: descr
= "16-bit ARGB 1-5-5-5 BE"; break;
1205 case V4L2_PIX_FMT_XRGB555X
: descr
= "16-bit XRGB 1-5-5-5 BE"; break;
1206 case V4L2_PIX_FMT_RGB565X
: descr
= "16-bit RGB 5-6-5 BE"; break;
1207 case V4L2_PIX_FMT_BGR666
: descr
= "18-bit BGRX 6-6-6-14"; break;
1208 case V4L2_PIX_FMT_BGR24
: descr
= "24-bit BGR 8-8-8"; break;
1209 case V4L2_PIX_FMT_RGB24
: descr
= "24-bit RGB 8-8-8"; break;
1210 case V4L2_PIX_FMT_BGR32
: descr
= "32-bit BGRA/X 8-8-8-8"; break;
1211 case V4L2_PIX_FMT_ABGR32
: descr
= "32-bit BGRA 8-8-8-8"; break;
1212 case V4L2_PIX_FMT_XBGR32
: descr
= "32-bit BGRX 8-8-8-8"; break;
1213 case V4L2_PIX_FMT_RGB32
: descr
= "32-bit A/XRGB 8-8-8-8"; break;
1214 case V4L2_PIX_FMT_ARGB32
: descr
= "32-bit ARGB 8-8-8-8"; break;
1215 case V4L2_PIX_FMT_XRGB32
: descr
= "32-bit XRGB 8-8-8-8"; break;
1216 case V4L2_PIX_FMT_BGRA32
: descr
= "32-bit ABGR 8-8-8-8"; break;
1217 case V4L2_PIX_FMT_BGRX32
: descr
= "32-bit XBGR 8-8-8-8"; break;
1218 case V4L2_PIX_FMT_RGBA32
: descr
= "32-bit RGBA 8-8-8-8"; break;
1219 case V4L2_PIX_FMT_RGBX32
: descr
= "32-bit RGBX 8-8-8-8"; break;
1220 case V4L2_PIX_FMT_GREY
: descr
= "8-bit Greyscale"; break;
1221 case V4L2_PIX_FMT_Y4
: descr
= "4-bit Greyscale"; break;
1222 case V4L2_PIX_FMT_Y6
: descr
= "6-bit Greyscale"; break;
1223 case V4L2_PIX_FMT_Y10
: descr
= "10-bit Greyscale"; break;
1224 case V4L2_PIX_FMT_Y12
: descr
= "12-bit Greyscale"; break;
1225 case V4L2_PIX_FMT_Y14
: descr
= "14-bit Greyscale"; break;
1226 case V4L2_PIX_FMT_Y16
: descr
= "16-bit Greyscale"; break;
1227 case V4L2_PIX_FMT_Y16_BE
: descr
= "16-bit Greyscale BE"; break;
1228 case V4L2_PIX_FMT_Y10BPACK
: descr
= "10-bit Greyscale (Packed)"; break;
1229 case V4L2_PIX_FMT_Y10P
: descr
= "10-bit Greyscale (MIPI Packed)"; break;
1230 case V4L2_PIX_FMT_Y8I
: descr
= "Interleaved 8-bit Greyscale"; break;
1231 case V4L2_PIX_FMT_Y12I
: descr
= "Interleaved 12-bit Greyscale"; break;
1232 case V4L2_PIX_FMT_Z16
: descr
= "16-bit Depth"; break;
1233 case V4L2_PIX_FMT_INZI
: descr
= "Planar 10:16 Greyscale Depth"; break;
1234 case V4L2_PIX_FMT_CNF4
: descr
= "4-bit Depth Confidence (Packed)"; break;
1235 case V4L2_PIX_FMT_PAL8
: descr
= "8-bit Palette"; break;
1236 case V4L2_PIX_FMT_UV8
: descr
= "8-bit Chrominance UV 4-4"; break;
1237 case V4L2_PIX_FMT_YVU410
: descr
= "Planar YVU 4:1:0"; break;
1238 case V4L2_PIX_FMT_YVU420
: descr
= "Planar YVU 4:2:0"; break;
1239 case V4L2_PIX_FMT_YUYV
: descr
= "YUYV 4:2:2"; break;
1240 case V4L2_PIX_FMT_YYUV
: descr
= "YYUV 4:2:2"; break;
1241 case V4L2_PIX_FMT_YVYU
: descr
= "YVYU 4:2:2"; break;
1242 case V4L2_PIX_FMT_UYVY
: descr
= "UYVY 4:2:2"; break;
1243 case V4L2_PIX_FMT_VYUY
: descr
= "VYUY 4:2:2"; break;
1244 case V4L2_PIX_FMT_YUV422P
: descr
= "Planar YUV 4:2:2"; break;
1245 case V4L2_PIX_FMT_YUV411P
: descr
= "Planar YUV 4:1:1"; break;
1246 case V4L2_PIX_FMT_Y41P
: descr
= "YUV 4:1:1 (Packed)"; break;
1247 case V4L2_PIX_FMT_YUV444
: descr
= "16-bit A/XYUV 4-4-4-4"; break;
1248 case V4L2_PIX_FMT_YUV555
: descr
= "16-bit A/XYUV 1-5-5-5"; break;
1249 case V4L2_PIX_FMT_YUV565
: descr
= "16-bit YUV 5-6-5"; break;
1250 case V4L2_PIX_FMT_YUV32
: descr
= "32-bit A/XYUV 8-8-8-8"; break;
1251 case V4L2_PIX_FMT_AYUV32
: descr
= "32-bit AYUV 8-8-8-8"; break;
1252 case V4L2_PIX_FMT_XYUV32
: descr
= "32-bit XYUV 8-8-8-8"; break;
1253 case V4L2_PIX_FMT_VUYA32
: descr
= "32-bit VUYA 8-8-8-8"; break;
1254 case V4L2_PIX_FMT_VUYX32
: descr
= "32-bit VUYX 8-8-8-8"; break;
1255 case V4L2_PIX_FMT_YUV410
: descr
= "Planar YUV 4:1:0"; break;
1256 case V4L2_PIX_FMT_YUV420
: descr
= "Planar YUV 4:2:0"; break;
1257 case V4L2_PIX_FMT_HI240
: descr
= "8-bit Dithered RGB (BTTV)"; break;
1258 case V4L2_PIX_FMT_HM12
: descr
= "YUV 4:2:0 (16x16 Macroblocks)"; break;
1259 case V4L2_PIX_FMT_M420
: descr
= "YUV 4:2:0 (M420)"; break;
1260 case V4L2_PIX_FMT_NV12
: descr
= "Y/CbCr 4:2:0"; break;
1261 case V4L2_PIX_FMT_NV21
: descr
= "Y/CrCb 4:2:0"; break;
1262 case V4L2_PIX_FMT_NV16
: descr
= "Y/CbCr 4:2:2"; break;
1263 case V4L2_PIX_FMT_NV61
: descr
= "Y/CrCb 4:2:2"; break;
1264 case V4L2_PIX_FMT_NV24
: descr
= "Y/CbCr 4:4:4"; break;
1265 case V4L2_PIX_FMT_NV42
: descr
= "Y/CrCb 4:4:4"; break;
1266 case V4L2_PIX_FMT_NV12M
: descr
= "Y/CbCr 4:2:0 (N-C)"; break;
1267 case V4L2_PIX_FMT_NV21M
: descr
= "Y/CrCb 4:2:0 (N-C)"; break;
1268 case V4L2_PIX_FMT_NV16M
: descr
= "Y/CbCr 4:2:2 (N-C)"; break;
1269 case V4L2_PIX_FMT_NV61M
: descr
= "Y/CrCb 4:2:2 (N-C)"; break;
1270 case V4L2_PIX_FMT_NV12MT
: descr
= "Y/CbCr 4:2:0 (64x32 MB, N-C)"; break;
1271 case V4L2_PIX_FMT_NV12MT_16X16
: descr
= "Y/CbCr 4:2:0 (16x16 MB, N-C)"; break;
1272 case V4L2_PIX_FMT_YUV420M
: descr
= "Planar YUV 4:2:0 (N-C)"; break;
1273 case V4L2_PIX_FMT_YVU420M
: descr
= "Planar YVU 4:2:0 (N-C)"; break;
1274 case V4L2_PIX_FMT_YUV422M
: descr
= "Planar YUV 4:2:2 (N-C)"; break;
1275 case V4L2_PIX_FMT_YVU422M
: descr
= "Planar YVU 4:2:2 (N-C)"; break;
1276 case V4L2_PIX_FMT_YUV444M
: descr
= "Planar YUV 4:4:4 (N-C)"; break;
1277 case V4L2_PIX_FMT_YVU444M
: descr
= "Planar YVU 4:4:4 (N-C)"; break;
1278 case V4L2_PIX_FMT_SBGGR8
: descr
= "8-bit Bayer BGBG/GRGR"; break;
1279 case V4L2_PIX_FMT_SGBRG8
: descr
= "8-bit Bayer GBGB/RGRG"; break;
1280 case V4L2_PIX_FMT_SGRBG8
: descr
= "8-bit Bayer GRGR/BGBG"; break;
1281 case V4L2_PIX_FMT_SRGGB8
: descr
= "8-bit Bayer RGRG/GBGB"; break;
1282 case V4L2_PIX_FMT_SBGGR10
: descr
= "10-bit Bayer BGBG/GRGR"; break;
1283 case V4L2_PIX_FMT_SGBRG10
: descr
= "10-bit Bayer GBGB/RGRG"; break;
1284 case V4L2_PIX_FMT_SGRBG10
: descr
= "10-bit Bayer GRGR/BGBG"; break;
1285 case V4L2_PIX_FMT_SRGGB10
: descr
= "10-bit Bayer RGRG/GBGB"; break;
1286 case V4L2_PIX_FMT_SBGGR10P
: descr
= "10-bit Bayer BGBG/GRGR Packed"; break;
1287 case V4L2_PIX_FMT_SGBRG10P
: descr
= "10-bit Bayer GBGB/RGRG Packed"; break;
1288 case V4L2_PIX_FMT_SGRBG10P
: descr
= "10-bit Bayer GRGR/BGBG Packed"; break;
1289 case V4L2_PIX_FMT_SRGGB10P
: descr
= "10-bit Bayer RGRG/GBGB Packed"; break;
1290 case V4L2_PIX_FMT_IPU3_SBGGR10
: descr
= "10-bit bayer BGGR IPU3 Packed"; break;
1291 case V4L2_PIX_FMT_IPU3_SGBRG10
: descr
= "10-bit bayer GBRG IPU3 Packed"; break;
1292 case V4L2_PIX_FMT_IPU3_SGRBG10
: descr
= "10-bit bayer GRBG IPU3 Packed"; break;
1293 case V4L2_PIX_FMT_IPU3_SRGGB10
: descr
= "10-bit bayer RGGB IPU3 Packed"; break;
1294 case V4L2_PIX_FMT_SBGGR10ALAW8
: descr
= "8-bit Bayer BGBG/GRGR (A-law)"; break;
1295 case V4L2_PIX_FMT_SGBRG10ALAW8
: descr
= "8-bit Bayer GBGB/RGRG (A-law)"; break;
1296 case V4L2_PIX_FMT_SGRBG10ALAW8
: descr
= "8-bit Bayer GRGR/BGBG (A-law)"; break;
1297 case V4L2_PIX_FMT_SRGGB10ALAW8
: descr
= "8-bit Bayer RGRG/GBGB (A-law)"; break;
1298 case V4L2_PIX_FMT_SBGGR10DPCM8
: descr
= "8-bit Bayer BGBG/GRGR (DPCM)"; break;
1299 case V4L2_PIX_FMT_SGBRG10DPCM8
: descr
= "8-bit Bayer GBGB/RGRG (DPCM)"; break;
1300 case V4L2_PIX_FMT_SGRBG10DPCM8
: descr
= "8-bit Bayer GRGR/BGBG (DPCM)"; break;
1301 case V4L2_PIX_FMT_SRGGB10DPCM8
: descr
= "8-bit Bayer RGRG/GBGB (DPCM)"; break;
1302 case V4L2_PIX_FMT_SBGGR12
: descr
= "12-bit Bayer BGBG/GRGR"; break;
1303 case V4L2_PIX_FMT_SGBRG12
: descr
= "12-bit Bayer GBGB/RGRG"; break;
1304 case V4L2_PIX_FMT_SGRBG12
: descr
= "12-bit Bayer GRGR/BGBG"; break;
1305 case V4L2_PIX_FMT_SRGGB12
: descr
= "12-bit Bayer RGRG/GBGB"; break;
1306 case V4L2_PIX_FMT_SBGGR12P
: descr
= "12-bit Bayer BGBG/GRGR Packed"; break;
1307 case V4L2_PIX_FMT_SGBRG12P
: descr
= "12-bit Bayer GBGB/RGRG Packed"; break;
1308 case V4L2_PIX_FMT_SGRBG12P
: descr
= "12-bit Bayer GRGR/BGBG Packed"; break;
1309 case V4L2_PIX_FMT_SRGGB12P
: descr
= "12-bit Bayer RGRG/GBGB Packed"; break;
1310 case V4L2_PIX_FMT_SBGGR14
: descr
= "14-bit Bayer BGBG/GRGR"; break;
1311 case V4L2_PIX_FMT_SGBRG14
: descr
= "14-bit Bayer GBGB/RGRG"; break;
1312 case V4L2_PIX_FMT_SGRBG14
: descr
= "14-bit Bayer GRGR/BGBG"; break;
1313 case V4L2_PIX_FMT_SRGGB14
: descr
= "14-bit Bayer RGRG/GBGB"; break;
1314 case V4L2_PIX_FMT_SBGGR14P
: descr
= "14-bit Bayer BGBG/GRGR Packed"; break;
1315 case V4L2_PIX_FMT_SGBRG14P
: descr
= "14-bit Bayer GBGB/RGRG Packed"; break;
1316 case V4L2_PIX_FMT_SGRBG14P
: descr
= "14-bit Bayer GRGR/BGBG Packed"; break;
1317 case V4L2_PIX_FMT_SRGGB14P
: descr
= "14-bit Bayer RGRG/GBGB Packed"; break;
1318 case V4L2_PIX_FMT_SBGGR16
: descr
= "16-bit Bayer BGBG/GRGR"; break;
1319 case V4L2_PIX_FMT_SGBRG16
: descr
= "16-bit Bayer GBGB/RGRG"; break;
1320 case V4L2_PIX_FMT_SGRBG16
: descr
= "16-bit Bayer GRGR/BGBG"; break;
1321 case V4L2_PIX_FMT_SRGGB16
: descr
= "16-bit Bayer RGRG/GBGB"; break;
1322 case V4L2_PIX_FMT_SN9C20X_I420
: descr
= "GSPCA SN9C20X I420"; break;
1323 case V4L2_PIX_FMT_SPCA501
: descr
= "GSPCA SPCA501"; break;
1324 case V4L2_PIX_FMT_SPCA505
: descr
= "GSPCA SPCA505"; break;
1325 case V4L2_PIX_FMT_SPCA508
: descr
= "GSPCA SPCA508"; break;
1326 case V4L2_PIX_FMT_STV0680
: descr
= "GSPCA STV0680"; break;
1327 case V4L2_PIX_FMT_TM6000
: descr
= "A/V + VBI Mux Packet"; break;
1328 case V4L2_PIX_FMT_CIT_YYVYUY
: descr
= "GSPCA CIT YYVYUY"; break;
1329 case V4L2_PIX_FMT_KONICA420
: descr
= "GSPCA KONICA420"; break;
1330 case V4L2_PIX_FMT_HSV24
: descr
= "24-bit HSV 8-8-8"; break;
1331 case V4L2_PIX_FMT_HSV32
: descr
= "32-bit XHSV 8-8-8-8"; break;
1332 case V4L2_SDR_FMT_CU8
: descr
= "Complex U8"; break;
1333 case V4L2_SDR_FMT_CU16LE
: descr
= "Complex U16LE"; break;
1334 case V4L2_SDR_FMT_CS8
: descr
= "Complex S8"; break;
1335 case V4L2_SDR_FMT_CS14LE
: descr
= "Complex S14LE"; break;
1336 case V4L2_SDR_FMT_RU12LE
: descr
= "Real U12LE"; break;
1337 case V4L2_SDR_FMT_PCU16BE
: descr
= "Planar Complex U16BE"; break;
1338 case V4L2_SDR_FMT_PCU18BE
: descr
= "Planar Complex U18BE"; break;
1339 case V4L2_SDR_FMT_PCU20BE
: descr
= "Planar Complex U20BE"; break;
1340 case V4L2_TCH_FMT_DELTA_TD16
: descr
= "16-bit Signed Deltas"; break;
1341 case V4L2_TCH_FMT_DELTA_TD08
: descr
= "8-bit Signed Deltas"; break;
1342 case V4L2_TCH_FMT_TU16
: descr
= "16-bit Unsigned Touch Data"; break;
1343 case V4L2_TCH_FMT_TU08
: descr
= "8-bit Unsigned Touch Data"; break;
1344 case V4L2_META_FMT_VSP1_HGO
: descr
= "R-Car VSP1 1-D Histogram"; break;
1345 case V4L2_META_FMT_VSP1_HGT
: descr
= "R-Car VSP1 2-D Histogram"; break;
1346 case V4L2_META_FMT_UVC
: descr
= "UVC Payload Header Metadata"; break;
1347 case V4L2_META_FMT_D4XX
: descr
= "Intel D4xx UVC Metadata"; break;
1348 case V4L2_META_FMT_VIVID
: descr
= "Vivid Metadata"; break;
1351 /* Compressed formats */
1352 flags
= V4L2_FMT_FLAG_COMPRESSED
;
1353 switch (fmt
->pixelformat
) {
1354 /* Max description length mask: descr = "0123456789012345678901234567890" */
1355 case V4L2_PIX_FMT_MJPEG
: descr
= "Motion-JPEG"; break;
1356 case V4L2_PIX_FMT_JPEG
: descr
= "JFIF JPEG"; break;
1357 case V4L2_PIX_FMT_DV
: descr
= "1394"; break;
1358 case V4L2_PIX_FMT_MPEG
: descr
= "MPEG-1/2/4"; break;
1359 case V4L2_PIX_FMT_H264
: descr
= "H.264"; break;
1360 case V4L2_PIX_FMT_H264_NO_SC
: descr
= "H.264 (No Start Codes)"; break;
1361 case V4L2_PIX_FMT_H264_MVC
: descr
= "H.264 MVC"; break;
1362 case V4L2_PIX_FMT_H264_SLICE
: descr
= "H.264 Parsed Slice Data"; break;
1363 case V4L2_PIX_FMT_H263
: descr
= "H.263"; break;
1364 case V4L2_PIX_FMT_MPEG1
: descr
= "MPEG-1 ES"; break;
1365 case V4L2_PIX_FMT_MPEG2
: descr
= "MPEG-2 ES"; break;
1366 case V4L2_PIX_FMT_MPEG2_SLICE
: descr
= "MPEG-2 Parsed Slice Data"; break;
1367 case V4L2_PIX_FMT_MPEG4
: descr
= "MPEG-4 Part 2 ES"; break;
1368 case V4L2_PIX_FMT_XVID
: descr
= "Xvid"; break;
1369 case V4L2_PIX_FMT_VC1_ANNEX_G
: descr
= "VC-1 (SMPTE 412M Annex G)"; break;
1370 case V4L2_PIX_FMT_VC1_ANNEX_L
: descr
= "VC-1 (SMPTE 412M Annex L)"; break;
1371 case V4L2_PIX_FMT_VP8
: descr
= "VP8"; break;
1372 case V4L2_PIX_FMT_VP8_FRAME
: descr
= "VP8 Frame"; break;
1373 case V4L2_PIX_FMT_VP9
: descr
= "VP9"; break;
1374 case V4L2_PIX_FMT_HEVC
: descr
= "HEVC"; break; /* aka H.265 */
1375 case V4L2_PIX_FMT_HEVC_SLICE
: descr
= "HEVC Parsed Slice Data"; break;
1376 case V4L2_PIX_FMT_FWHT
: descr
= "FWHT"; break; /* used in vicodec */
1377 case V4L2_PIX_FMT_FWHT_STATELESS
: descr
= "FWHT Stateless"; break; /* used in vicodec */
1378 case V4L2_PIX_FMT_CPIA1
: descr
= "GSPCA CPiA YUV"; break;
1379 case V4L2_PIX_FMT_WNVA
: descr
= "WNVA"; break;
1380 case V4L2_PIX_FMT_SN9C10X
: descr
= "GSPCA SN9C10X"; break;
1381 case V4L2_PIX_FMT_PWC1
: descr
= "Raw Philips Webcam Type (Old)"; break;
1382 case V4L2_PIX_FMT_PWC2
: descr
= "Raw Philips Webcam Type (New)"; break;
1383 case V4L2_PIX_FMT_ET61X251
: descr
= "GSPCA ET61X251"; break;
1384 case V4L2_PIX_FMT_SPCA561
: descr
= "GSPCA SPCA561"; break;
1385 case V4L2_PIX_FMT_PAC207
: descr
= "GSPCA PAC207"; break;
1386 case V4L2_PIX_FMT_MR97310A
: descr
= "GSPCA MR97310A"; break;
1387 case V4L2_PIX_FMT_JL2005BCD
: descr
= "GSPCA JL2005BCD"; break;
1388 case V4L2_PIX_FMT_SN9C2028
: descr
= "GSPCA SN9C2028"; break;
1389 case V4L2_PIX_FMT_SQ905C
: descr
= "GSPCA SQ905C"; break;
1390 case V4L2_PIX_FMT_PJPG
: descr
= "GSPCA PJPG"; break;
1391 case V4L2_PIX_FMT_OV511
: descr
= "GSPCA OV511"; break;
1392 case V4L2_PIX_FMT_OV518
: descr
= "GSPCA OV518"; break;
1393 case V4L2_PIX_FMT_JPGL
: descr
= "JPEG Lite"; break;
1394 case V4L2_PIX_FMT_SE401
: descr
= "GSPCA SE401"; break;
1395 case V4L2_PIX_FMT_S5C_UYVY_JPG
: descr
= "S5C73MX interleaved UYVY/JPEG"; break;
1396 case V4L2_PIX_FMT_MT21C
: descr
= "Mediatek Compressed Format"; break;
1397 case V4L2_PIX_FMT_SUNXI_TILED_NV12
: descr
= "Sunxi Tiled NV12 Format"; break;
1399 if (fmt
->description
[0])
1401 WARN(1, "Unknown pixelformat 0x%08x\n", fmt
->pixelformat
);
1403 snprintf(fmt
->description
, sz
, "%c%c%c%c%s",
1404 (char)(fmt
->pixelformat
& 0x7f),
1405 (char)((fmt
->pixelformat
>> 8) & 0x7f),
1406 (char)((fmt
->pixelformat
>> 16) & 0x7f),
1407 (char)((fmt
->pixelformat
>> 24) & 0x7f),
1408 (fmt
->pixelformat
& (1UL << 31)) ? "-BE" : "");
1414 WARN_ON(strscpy(fmt
->description
, descr
, sz
) < 0);
1415 fmt
->flags
|= flags
;
1418 static int v4l_enum_fmt(const struct v4l2_ioctl_ops
*ops
,
1419 struct file
*file
, void *fh
, void *arg
)
1421 struct video_device
*vdev
= video_devdata(file
);
1422 struct v4l2_fmtdesc
*p
= arg
;
1423 int ret
= check_fmt(file
, p
->type
);
1431 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1432 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1433 cap_mask
= V4L2_CAP_VIDEO_CAPTURE_MPLANE
|
1434 V4L2_CAP_VIDEO_M2M_MPLANE
;
1435 if (!!(vdev
->device_caps
& cap_mask
) !=
1436 (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
))
1439 if (unlikely(!ops
->vidioc_enum_fmt_vid_cap
))
1441 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, arg
);
1443 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1444 if (unlikely(!ops
->vidioc_enum_fmt_vid_overlay
))
1446 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
, fh
, arg
);
1448 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1449 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1450 cap_mask
= V4L2_CAP_VIDEO_OUTPUT_MPLANE
|
1451 V4L2_CAP_VIDEO_M2M_MPLANE
;
1452 if (!!(vdev
->device_caps
& cap_mask
) !=
1453 (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
))
1456 if (unlikely(!ops
->vidioc_enum_fmt_vid_out
))
1458 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, arg
);
1460 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1461 if (unlikely(!ops
->vidioc_enum_fmt_sdr_cap
))
1463 ret
= ops
->vidioc_enum_fmt_sdr_cap(file
, fh
, arg
);
1465 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1466 if (unlikely(!ops
->vidioc_enum_fmt_sdr_out
))
1468 ret
= ops
->vidioc_enum_fmt_sdr_out(file
, fh
, arg
);
1470 case V4L2_BUF_TYPE_META_CAPTURE
:
1471 if (unlikely(!ops
->vidioc_enum_fmt_meta_cap
))
1473 ret
= ops
->vidioc_enum_fmt_meta_cap(file
, fh
, arg
);
1475 case V4L2_BUF_TYPE_META_OUTPUT
:
1476 if (unlikely(!ops
->vidioc_enum_fmt_meta_out
))
1478 ret
= ops
->vidioc_enum_fmt_meta_out(file
, fh
, arg
);
1482 v4l_fill_fmtdesc(p
);
1486 static void v4l_pix_format_touch(struct v4l2_pix_format
*p
)
1489 * The v4l2_pix_format structure contains fields that make no sense for
1490 * touch. Set them to default values in this case.
1493 p
->field
= V4L2_FIELD_NONE
;
1494 p
->colorspace
= V4L2_COLORSPACE_RAW
;
1497 p
->quantization
= 0;
1501 static int v4l_g_fmt(const struct v4l2_ioctl_ops
*ops
,
1502 struct file
*file
, void *fh
, void *arg
)
1504 struct v4l2_format
*p
= arg
;
1505 struct video_device
*vfd
= video_devdata(file
);
1506 int ret
= check_fmt(file
, p
->type
);
1512 * fmt can't be cleared for these overlay types due to the 'clips'
1513 * 'clipcount' and 'bitmap' pointers in struct v4l2_window.
1514 * Those are provided by the user. So handle these two overlay types
1515 * first, and then just do a simple memset for the other types.
1518 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1519 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
: {
1520 struct v4l2_clip __user
*clips
= p
->fmt
.win
.clips
;
1521 u32 clipcount
= p
->fmt
.win
.clipcount
;
1522 void __user
*bitmap
= p
->fmt
.win
.bitmap
;
1524 memset(&p
->fmt
, 0, sizeof(p
->fmt
));
1525 p
->fmt
.win
.clips
= clips
;
1526 p
->fmt
.win
.clipcount
= clipcount
;
1527 p
->fmt
.win
.bitmap
= bitmap
;
1531 memset(&p
->fmt
, 0, sizeof(p
->fmt
));
1536 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1537 if (unlikely(!ops
->vidioc_g_fmt_vid_cap
))
1539 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1540 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, arg
);
1541 /* just in case the driver zeroed it again */
1542 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1543 if (vfd
->vfl_type
== VFL_TYPE_TOUCH
)
1544 v4l_pix_format_touch(&p
->fmt
.pix
);
1546 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1547 return ops
->vidioc_g_fmt_vid_cap_mplane(file
, fh
, arg
);
1548 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1549 return ops
->vidioc_g_fmt_vid_overlay(file
, fh
, arg
);
1550 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1551 return ops
->vidioc_g_fmt_vbi_cap(file
, fh
, arg
);
1552 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
1553 return ops
->vidioc_g_fmt_sliced_vbi_cap(file
, fh
, arg
);
1554 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1555 if (unlikely(!ops
->vidioc_g_fmt_vid_out
))
1557 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1558 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, arg
);
1559 /* just in case the driver zeroed it again */
1560 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1562 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1563 return ops
->vidioc_g_fmt_vid_out_mplane(file
, fh
, arg
);
1564 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
1565 return ops
->vidioc_g_fmt_vid_out_overlay(file
, fh
, arg
);
1566 case V4L2_BUF_TYPE_VBI_OUTPUT
:
1567 return ops
->vidioc_g_fmt_vbi_out(file
, fh
, arg
);
1568 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1569 return ops
->vidioc_g_fmt_sliced_vbi_out(file
, fh
, arg
);
1570 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1571 return ops
->vidioc_g_fmt_sdr_cap(file
, fh
, arg
);
1572 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1573 return ops
->vidioc_g_fmt_sdr_out(file
, fh
, arg
);
1574 case V4L2_BUF_TYPE_META_CAPTURE
:
1575 return ops
->vidioc_g_fmt_meta_cap(file
, fh
, arg
);
1576 case V4L2_BUF_TYPE_META_OUTPUT
:
1577 return ops
->vidioc_g_fmt_meta_out(file
, fh
, arg
);
1582 static int v4l_s_fmt(const struct v4l2_ioctl_ops
*ops
,
1583 struct file
*file
, void *fh
, void *arg
)
1585 struct v4l2_format
*p
= arg
;
1586 struct video_device
*vfd
= video_devdata(file
);
1587 int ret
= check_fmt(file
, p
->type
);
1593 ret
= v4l_enable_media_source(vfd
);
1596 v4l_sanitize_format(p
);
1599 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1600 if (unlikely(!ops
->vidioc_s_fmt_vid_cap
))
1602 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1603 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, arg
);
1604 /* just in case the driver zeroed it again */
1605 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1606 if (vfd
->vfl_type
== VFL_TYPE_TOUCH
)
1607 v4l_pix_format_touch(&p
->fmt
.pix
);
1609 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1610 if (unlikely(!ops
->vidioc_s_fmt_vid_cap_mplane
))
1612 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1613 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1614 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1616 return ops
->vidioc_s_fmt_vid_cap_mplane(file
, fh
, arg
);
1617 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1618 if (unlikely(!ops
->vidioc_s_fmt_vid_overlay
))
1620 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1621 return ops
->vidioc_s_fmt_vid_overlay(file
, fh
, arg
);
1622 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1623 if (unlikely(!ops
->vidioc_s_fmt_vbi_cap
))
1625 CLEAR_AFTER_FIELD(p
, fmt
.vbi
.flags
);
1626 return ops
->vidioc_s_fmt_vbi_cap(file
, fh
, arg
);
1627 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
1628 if (unlikely(!ops
->vidioc_s_fmt_sliced_vbi_cap
))
1630 CLEAR_AFTER_FIELD(p
, fmt
.sliced
.io_size
);
1631 return ops
->vidioc_s_fmt_sliced_vbi_cap(file
, fh
, arg
);
1632 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1633 if (unlikely(!ops
->vidioc_s_fmt_vid_out
))
1635 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1636 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, arg
);
1637 /* just in case the driver zeroed it again */
1638 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1640 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1641 if (unlikely(!ops
->vidioc_s_fmt_vid_out_mplane
))
1643 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1644 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1645 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1647 return ops
->vidioc_s_fmt_vid_out_mplane(file
, fh
, arg
);
1648 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
1649 if (unlikely(!ops
->vidioc_s_fmt_vid_out_overlay
))
1651 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1652 return ops
->vidioc_s_fmt_vid_out_overlay(file
, fh
, arg
);
1653 case V4L2_BUF_TYPE_VBI_OUTPUT
:
1654 if (unlikely(!ops
->vidioc_s_fmt_vbi_out
))
1656 CLEAR_AFTER_FIELD(p
, fmt
.vbi
.flags
);
1657 return ops
->vidioc_s_fmt_vbi_out(file
, fh
, arg
);
1658 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1659 if (unlikely(!ops
->vidioc_s_fmt_sliced_vbi_out
))
1661 CLEAR_AFTER_FIELD(p
, fmt
.sliced
.io_size
);
1662 return ops
->vidioc_s_fmt_sliced_vbi_out(file
, fh
, arg
);
1663 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1664 if (unlikely(!ops
->vidioc_s_fmt_sdr_cap
))
1666 CLEAR_AFTER_FIELD(p
, fmt
.sdr
.buffersize
);
1667 return ops
->vidioc_s_fmt_sdr_cap(file
, fh
, arg
);
1668 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1669 if (unlikely(!ops
->vidioc_s_fmt_sdr_out
))
1671 CLEAR_AFTER_FIELD(p
, fmt
.sdr
.buffersize
);
1672 return ops
->vidioc_s_fmt_sdr_out(file
, fh
, arg
);
1673 case V4L2_BUF_TYPE_META_CAPTURE
:
1674 if (unlikely(!ops
->vidioc_s_fmt_meta_cap
))
1676 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1677 return ops
->vidioc_s_fmt_meta_cap(file
, fh
, arg
);
1678 case V4L2_BUF_TYPE_META_OUTPUT
:
1679 if (unlikely(!ops
->vidioc_s_fmt_meta_out
))
1681 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1682 return ops
->vidioc_s_fmt_meta_out(file
, fh
, arg
);
1687 static int v4l_try_fmt(const struct v4l2_ioctl_ops
*ops
,
1688 struct file
*file
, void *fh
, void *arg
)
1690 struct v4l2_format
*p
= arg
;
1691 struct video_device
*vfd
= video_devdata(file
);
1692 int ret
= check_fmt(file
, p
->type
);
1698 v4l_sanitize_format(p
);
1701 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1702 if (unlikely(!ops
->vidioc_try_fmt_vid_cap
))
1704 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1705 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, arg
);
1706 /* just in case the driver zeroed it again */
1707 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1708 if (vfd
->vfl_type
== VFL_TYPE_TOUCH
)
1709 v4l_pix_format_touch(&p
->fmt
.pix
);
1711 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1712 if (unlikely(!ops
->vidioc_try_fmt_vid_cap_mplane
))
1714 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1715 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1716 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1718 return ops
->vidioc_try_fmt_vid_cap_mplane(file
, fh
, arg
);
1719 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1720 if (unlikely(!ops
->vidioc_try_fmt_vid_overlay
))
1722 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1723 return ops
->vidioc_try_fmt_vid_overlay(file
, fh
, arg
);
1724 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1725 if (unlikely(!ops
->vidioc_try_fmt_vbi_cap
))
1727 CLEAR_AFTER_FIELD(p
, fmt
.vbi
.flags
);
1728 return ops
->vidioc_try_fmt_vbi_cap(file
, fh
, arg
);
1729 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
1730 if (unlikely(!ops
->vidioc_try_fmt_sliced_vbi_cap
))
1732 CLEAR_AFTER_FIELD(p
, fmt
.sliced
.io_size
);
1733 return ops
->vidioc_try_fmt_sliced_vbi_cap(file
, fh
, arg
);
1734 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1735 if (unlikely(!ops
->vidioc_try_fmt_vid_out
))
1737 CLEAR_AFTER_FIELD(p
, fmt
.pix
);
1738 ret
= ops
->vidioc_try_fmt_vid_out(file
, fh
, arg
);
1739 /* just in case the driver zeroed it again */
1740 p
->fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
1742 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1743 if (unlikely(!ops
->vidioc_try_fmt_vid_out_mplane
))
1745 CLEAR_AFTER_FIELD(p
, fmt
.pix_mp
.xfer_func
);
1746 for (i
= 0; i
< p
->fmt
.pix_mp
.num_planes
; i
++)
1747 CLEAR_AFTER_FIELD(&p
->fmt
.pix_mp
.plane_fmt
[i
],
1749 return ops
->vidioc_try_fmt_vid_out_mplane(file
, fh
, arg
);
1750 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
1751 if (unlikely(!ops
->vidioc_try_fmt_vid_out_overlay
))
1753 CLEAR_AFTER_FIELD(p
, fmt
.win
);
1754 return ops
->vidioc_try_fmt_vid_out_overlay(file
, fh
, arg
);
1755 case V4L2_BUF_TYPE_VBI_OUTPUT
:
1756 if (unlikely(!ops
->vidioc_try_fmt_vbi_out
))
1758 CLEAR_AFTER_FIELD(p
, fmt
.vbi
.flags
);
1759 return ops
->vidioc_try_fmt_vbi_out(file
, fh
, arg
);
1760 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1761 if (unlikely(!ops
->vidioc_try_fmt_sliced_vbi_out
))
1763 CLEAR_AFTER_FIELD(p
, fmt
.sliced
.io_size
);
1764 return ops
->vidioc_try_fmt_sliced_vbi_out(file
, fh
, arg
);
1765 case V4L2_BUF_TYPE_SDR_CAPTURE
:
1766 if (unlikely(!ops
->vidioc_try_fmt_sdr_cap
))
1768 CLEAR_AFTER_FIELD(p
, fmt
.sdr
.buffersize
);
1769 return ops
->vidioc_try_fmt_sdr_cap(file
, fh
, arg
);
1770 case V4L2_BUF_TYPE_SDR_OUTPUT
:
1771 if (unlikely(!ops
->vidioc_try_fmt_sdr_out
))
1773 CLEAR_AFTER_FIELD(p
, fmt
.sdr
.buffersize
);
1774 return ops
->vidioc_try_fmt_sdr_out(file
, fh
, arg
);
1775 case V4L2_BUF_TYPE_META_CAPTURE
:
1776 if (unlikely(!ops
->vidioc_try_fmt_meta_cap
))
1778 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1779 return ops
->vidioc_try_fmt_meta_cap(file
, fh
, arg
);
1780 case V4L2_BUF_TYPE_META_OUTPUT
:
1781 if (unlikely(!ops
->vidioc_try_fmt_meta_out
))
1783 CLEAR_AFTER_FIELD(p
, fmt
.meta
);
1784 return ops
->vidioc_try_fmt_meta_out(file
, fh
, arg
);
1789 static int v4l_streamon(const struct v4l2_ioctl_ops
*ops
,
1790 struct file
*file
, void *fh
, void *arg
)
1792 return ops
->vidioc_streamon(file
, fh
, *(unsigned int *)arg
);
1795 static int v4l_streamoff(const struct v4l2_ioctl_ops
*ops
,
1796 struct file
*file
, void *fh
, void *arg
)
1798 return ops
->vidioc_streamoff(file
, fh
, *(unsigned int *)arg
);
1801 static int v4l_g_tuner(const struct v4l2_ioctl_ops
*ops
,
1802 struct file
*file
, void *fh
, void *arg
)
1804 struct video_device
*vfd
= video_devdata(file
);
1805 struct v4l2_tuner
*p
= arg
;
1808 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1809 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1810 err
= ops
->vidioc_g_tuner(file
, fh
, p
);
1812 p
->capability
|= V4L2_TUNER_CAP_FREQ_BANDS
;
1816 static int v4l_s_tuner(const struct v4l2_ioctl_ops
*ops
,
1817 struct file
*file
, void *fh
, void *arg
)
1819 struct video_device
*vfd
= video_devdata(file
);
1820 struct v4l2_tuner
*p
= arg
;
1823 ret
= v4l_enable_media_source(vfd
);
1826 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1827 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1828 return ops
->vidioc_s_tuner(file
, fh
, p
);
1831 static int v4l_g_modulator(const struct v4l2_ioctl_ops
*ops
,
1832 struct file
*file
, void *fh
, void *arg
)
1834 struct video_device
*vfd
= video_devdata(file
);
1835 struct v4l2_modulator
*p
= arg
;
1838 if (vfd
->vfl_type
== VFL_TYPE_RADIO
)
1839 p
->type
= V4L2_TUNER_RADIO
;
1841 err
= ops
->vidioc_g_modulator(file
, fh
, p
);
1843 p
->capability
|= V4L2_TUNER_CAP_FREQ_BANDS
;
1847 static int v4l_s_modulator(const struct v4l2_ioctl_ops
*ops
,
1848 struct file
*file
, void *fh
, void *arg
)
1850 struct video_device
*vfd
= video_devdata(file
);
1851 struct v4l2_modulator
*p
= arg
;
1853 if (vfd
->vfl_type
== VFL_TYPE_RADIO
)
1854 p
->type
= V4L2_TUNER_RADIO
;
1856 return ops
->vidioc_s_modulator(file
, fh
, p
);
1859 static int v4l_g_frequency(const struct v4l2_ioctl_ops
*ops
,
1860 struct file
*file
, void *fh
, void *arg
)
1862 struct video_device
*vfd
= video_devdata(file
);
1863 struct v4l2_frequency
*p
= arg
;
1865 if (vfd
->vfl_type
== VFL_TYPE_SDR
)
1866 p
->type
= V4L2_TUNER_SDR
;
1868 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1869 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1870 return ops
->vidioc_g_frequency(file
, fh
, p
);
1873 static int v4l_s_frequency(const struct v4l2_ioctl_ops
*ops
,
1874 struct file
*file
, void *fh
, void *arg
)
1876 struct video_device
*vfd
= video_devdata(file
);
1877 const struct v4l2_frequency
*p
= arg
;
1878 enum v4l2_tuner_type type
;
1881 ret
= v4l_enable_media_source(vfd
);
1884 if (vfd
->vfl_type
== VFL_TYPE_SDR
) {
1885 if (p
->type
!= V4L2_TUNER_SDR
&& p
->type
!= V4L2_TUNER_RF
)
1888 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1889 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1890 if (type
!= p
->type
)
1893 return ops
->vidioc_s_frequency(file
, fh
, p
);
1896 static int v4l_enumstd(const struct v4l2_ioctl_ops
*ops
,
1897 struct file
*file
, void *fh
, void *arg
)
1899 struct video_device
*vfd
= video_devdata(file
);
1900 struct v4l2_standard
*p
= arg
;
1902 return v4l_video_std_enumstd(p
, vfd
->tvnorms
);
1905 static int v4l_s_std(const struct v4l2_ioctl_ops
*ops
,
1906 struct file
*file
, void *fh
, void *arg
)
1908 struct video_device
*vfd
= video_devdata(file
);
1909 v4l2_std_id id
= *(v4l2_std_id
*)arg
, norm
;
1912 ret
= v4l_enable_media_source(vfd
);
1915 norm
= id
& vfd
->tvnorms
;
1916 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1919 /* Calls the specific handler */
1920 return ops
->vidioc_s_std(file
, fh
, norm
);
1923 static int v4l_querystd(const struct v4l2_ioctl_ops
*ops
,
1924 struct file
*file
, void *fh
, void *arg
)
1926 struct video_device
*vfd
= video_devdata(file
);
1927 v4l2_std_id
*p
= arg
;
1930 ret
= v4l_enable_media_source(vfd
);
1934 * If no signal is detected, then the driver should return
1935 * V4L2_STD_UNKNOWN. Otherwise it should return tvnorms with
1936 * any standards that do not apply removed.
1938 * This means that tuners, audio and video decoders can join
1939 * their efforts to improve the standards detection.
1942 return ops
->vidioc_querystd(file
, fh
, arg
);
1945 static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops
*ops
,
1946 struct file
*file
, void *fh
, void *arg
)
1948 struct video_device
*vfd
= video_devdata(file
);
1949 struct v4l2_hw_freq_seek
*p
= arg
;
1950 enum v4l2_tuner_type type
;
1953 ret
= v4l_enable_media_source(vfd
);
1956 /* s_hw_freq_seek is not supported for SDR for now */
1957 if (vfd
->vfl_type
== VFL_TYPE_SDR
)
1960 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1961 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1962 if (p
->type
!= type
)
1964 return ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
1967 static int v4l_overlay(const struct v4l2_ioctl_ops
*ops
,
1968 struct file
*file
, void *fh
, void *arg
)
1970 return ops
->vidioc_overlay(file
, fh
, *(unsigned int *)arg
);
1973 static int v4l_reqbufs(const struct v4l2_ioctl_ops
*ops
,
1974 struct file
*file
, void *fh
, void *arg
)
1976 struct v4l2_requestbuffers
*p
= arg
;
1977 int ret
= check_fmt(file
, p
->type
);
1982 CLEAR_AFTER_FIELD(p
, capabilities
);
1984 return ops
->vidioc_reqbufs(file
, fh
, p
);
1987 static int v4l_querybuf(const struct v4l2_ioctl_ops
*ops
,
1988 struct file
*file
, void *fh
, void *arg
)
1990 struct v4l2_buffer
*p
= arg
;
1991 int ret
= check_fmt(file
, p
->type
);
1993 return ret
? ret
: ops
->vidioc_querybuf(file
, fh
, p
);
1996 static int v4l_qbuf(const struct v4l2_ioctl_ops
*ops
,
1997 struct file
*file
, void *fh
, void *arg
)
1999 struct v4l2_buffer
*p
= arg
;
2000 int ret
= check_fmt(file
, p
->type
);
2002 return ret
? ret
: ops
->vidioc_qbuf(file
, fh
, p
);
2005 static int v4l_dqbuf(const struct v4l2_ioctl_ops
*ops
,
2006 struct file
*file
, void *fh
, void *arg
)
2008 struct v4l2_buffer
*p
= arg
;
2009 int ret
= check_fmt(file
, p
->type
);
2011 return ret
? ret
: ops
->vidioc_dqbuf(file
, fh
, p
);
2014 static int v4l_create_bufs(const struct v4l2_ioctl_ops
*ops
,
2015 struct file
*file
, void *fh
, void *arg
)
2017 struct v4l2_create_buffers
*create
= arg
;
2018 int ret
= check_fmt(file
, create
->format
.type
);
2023 CLEAR_AFTER_FIELD(create
, capabilities
);
2025 v4l_sanitize_format(&create
->format
);
2027 ret
= ops
->vidioc_create_bufs(file
, fh
, create
);
2029 if (create
->format
.type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
||
2030 create
->format
.type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
2031 create
->format
.fmt
.pix
.priv
= V4L2_PIX_FMT_PRIV_MAGIC
;
2036 static int v4l_prepare_buf(const struct v4l2_ioctl_ops
*ops
,
2037 struct file
*file
, void *fh
, void *arg
)
2039 struct v4l2_buffer
*b
= arg
;
2040 int ret
= check_fmt(file
, b
->type
);
2042 return ret
? ret
: ops
->vidioc_prepare_buf(file
, fh
, b
);
2045 static int v4l_g_parm(const struct v4l2_ioctl_ops
*ops
,
2046 struct file
*file
, void *fh
, void *arg
)
2048 struct v4l2_streamparm
*p
= arg
;
2050 int ret
= check_fmt(file
, p
->type
);
2054 if (ops
->vidioc_g_parm
)
2055 return ops
->vidioc_g_parm(file
, fh
, p
);
2056 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
2057 p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2059 p
->parm
.capture
.readbuffers
= 2;
2060 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
2062 v4l2_video_std_frame_period(std
, &p
->parm
.capture
.timeperframe
);
2066 static int v4l_s_parm(const struct v4l2_ioctl_ops
*ops
,
2067 struct file
*file
, void *fh
, void *arg
)
2069 struct v4l2_streamparm
*p
= arg
;
2070 int ret
= check_fmt(file
, p
->type
);
2075 /* Note: extendedmode is never used in drivers */
2076 if (V4L2_TYPE_IS_OUTPUT(p
->type
)) {
2077 memset(p
->parm
.output
.reserved
, 0,
2078 sizeof(p
->parm
.output
.reserved
));
2079 p
->parm
.output
.extendedmode
= 0;
2080 p
->parm
.output
.outputmode
&= V4L2_MODE_HIGHQUALITY
;
2082 memset(p
->parm
.capture
.reserved
, 0,
2083 sizeof(p
->parm
.capture
.reserved
));
2084 p
->parm
.capture
.extendedmode
= 0;
2085 p
->parm
.capture
.capturemode
&= V4L2_MODE_HIGHQUALITY
;
2087 return ops
->vidioc_s_parm(file
, fh
, p
);
2090 static int v4l_queryctrl(const struct v4l2_ioctl_ops
*ops
,
2091 struct file
*file
, void *fh
, void *arg
)
2093 struct video_device
*vfd
= video_devdata(file
);
2094 struct v4l2_queryctrl
*p
= arg
;
2095 struct v4l2_fh
*vfh
=
2096 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2098 if (vfh
&& vfh
->ctrl_handler
)
2099 return v4l2_queryctrl(vfh
->ctrl_handler
, p
);
2100 if (vfd
->ctrl_handler
)
2101 return v4l2_queryctrl(vfd
->ctrl_handler
, p
);
2102 if (ops
->vidioc_queryctrl
)
2103 return ops
->vidioc_queryctrl(file
, fh
, p
);
2107 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops
*ops
,
2108 struct file
*file
, void *fh
, void *arg
)
2110 struct video_device
*vfd
= video_devdata(file
);
2111 struct v4l2_query_ext_ctrl
*p
= arg
;
2112 struct v4l2_fh
*vfh
=
2113 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2115 if (vfh
&& vfh
->ctrl_handler
)
2116 return v4l2_query_ext_ctrl(vfh
->ctrl_handler
, p
);
2117 if (vfd
->ctrl_handler
)
2118 return v4l2_query_ext_ctrl(vfd
->ctrl_handler
, p
);
2119 if (ops
->vidioc_query_ext_ctrl
)
2120 return ops
->vidioc_query_ext_ctrl(file
, fh
, p
);
2124 static int v4l_querymenu(const struct v4l2_ioctl_ops
*ops
,
2125 struct file
*file
, void *fh
, void *arg
)
2127 struct video_device
*vfd
= video_devdata(file
);
2128 struct v4l2_querymenu
*p
= arg
;
2129 struct v4l2_fh
*vfh
=
2130 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2132 if (vfh
&& vfh
->ctrl_handler
)
2133 return v4l2_querymenu(vfh
->ctrl_handler
, p
);
2134 if (vfd
->ctrl_handler
)
2135 return v4l2_querymenu(vfd
->ctrl_handler
, p
);
2136 if (ops
->vidioc_querymenu
)
2137 return ops
->vidioc_querymenu(file
, fh
, p
);
2141 static int v4l_g_ctrl(const struct v4l2_ioctl_ops
*ops
,
2142 struct file
*file
, void *fh
, void *arg
)
2144 struct video_device
*vfd
= video_devdata(file
);
2145 struct v4l2_control
*p
= arg
;
2146 struct v4l2_fh
*vfh
=
2147 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2148 struct v4l2_ext_controls ctrls
;
2149 struct v4l2_ext_control ctrl
;
2151 if (vfh
&& vfh
->ctrl_handler
)
2152 return v4l2_g_ctrl(vfh
->ctrl_handler
, p
);
2153 if (vfd
->ctrl_handler
)
2154 return v4l2_g_ctrl(vfd
->ctrl_handler
, p
);
2155 if (ops
->vidioc_g_ctrl
)
2156 return ops
->vidioc_g_ctrl(file
, fh
, p
);
2157 if (ops
->vidioc_g_ext_ctrls
== NULL
)
2160 ctrls
.which
= V4L2_CTRL_ID2WHICH(p
->id
);
2162 ctrls
.controls
= &ctrl
;
2164 ctrl
.value
= p
->value
;
2165 if (check_ext_ctrls(&ctrls
, 1)) {
2166 int ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
2169 p
->value
= ctrl
.value
;
2175 static int v4l_s_ctrl(const struct v4l2_ioctl_ops
*ops
,
2176 struct file
*file
, void *fh
, void *arg
)
2178 struct video_device
*vfd
= video_devdata(file
);
2179 struct v4l2_control
*p
= arg
;
2180 struct v4l2_fh
*vfh
=
2181 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2182 struct v4l2_ext_controls ctrls
;
2183 struct v4l2_ext_control ctrl
;
2185 if (vfh
&& vfh
->ctrl_handler
)
2186 return v4l2_s_ctrl(vfh
, vfh
->ctrl_handler
, p
);
2187 if (vfd
->ctrl_handler
)
2188 return v4l2_s_ctrl(NULL
, vfd
->ctrl_handler
, p
);
2189 if (ops
->vidioc_s_ctrl
)
2190 return ops
->vidioc_s_ctrl(file
, fh
, p
);
2191 if (ops
->vidioc_s_ext_ctrls
== NULL
)
2194 ctrls
.which
= V4L2_CTRL_ID2WHICH(p
->id
);
2196 ctrls
.controls
= &ctrl
;
2198 ctrl
.value
= p
->value
;
2199 if (check_ext_ctrls(&ctrls
, 1))
2200 return ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
2204 static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops
*ops
,
2205 struct file
*file
, void *fh
, void *arg
)
2207 struct video_device
*vfd
= video_devdata(file
);
2208 struct v4l2_ext_controls
*p
= arg
;
2209 struct v4l2_fh
*vfh
=
2210 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2212 p
->error_idx
= p
->count
;
2213 if (vfh
&& vfh
->ctrl_handler
)
2214 return v4l2_g_ext_ctrls(vfh
->ctrl_handler
,
2215 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2216 if (vfd
->ctrl_handler
)
2217 return v4l2_g_ext_ctrls(vfd
->ctrl_handler
,
2218 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2219 if (ops
->vidioc_g_ext_ctrls
== NULL
)
2221 return check_ext_ctrls(p
, 0) ? ops
->vidioc_g_ext_ctrls(file
, fh
, p
) :
2225 static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops
*ops
,
2226 struct file
*file
, void *fh
, void *arg
)
2228 struct video_device
*vfd
= video_devdata(file
);
2229 struct v4l2_ext_controls
*p
= arg
;
2230 struct v4l2_fh
*vfh
=
2231 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2233 p
->error_idx
= p
->count
;
2234 if (vfh
&& vfh
->ctrl_handler
)
2235 return v4l2_s_ext_ctrls(vfh
, vfh
->ctrl_handler
,
2236 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2237 if (vfd
->ctrl_handler
)
2238 return v4l2_s_ext_ctrls(NULL
, vfd
->ctrl_handler
,
2239 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2240 if (ops
->vidioc_s_ext_ctrls
== NULL
)
2242 return check_ext_ctrls(p
, 0) ? ops
->vidioc_s_ext_ctrls(file
, fh
, p
) :
2246 static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops
*ops
,
2247 struct file
*file
, void *fh
, void *arg
)
2249 struct video_device
*vfd
= video_devdata(file
);
2250 struct v4l2_ext_controls
*p
= arg
;
2251 struct v4l2_fh
*vfh
=
2252 test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
) ? fh
: NULL
;
2254 p
->error_idx
= p
->count
;
2255 if (vfh
&& vfh
->ctrl_handler
)
2256 return v4l2_try_ext_ctrls(vfh
->ctrl_handler
,
2257 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2258 if (vfd
->ctrl_handler
)
2259 return v4l2_try_ext_ctrls(vfd
->ctrl_handler
,
2260 vfd
, vfd
->v4l2_dev
->mdev
, p
);
2261 if (ops
->vidioc_try_ext_ctrls
== NULL
)
2263 return check_ext_ctrls(p
, 0) ? ops
->vidioc_try_ext_ctrls(file
, fh
, p
) :
2268 * The selection API specified originally that the _MPLANE buffer types
2269 * shouldn't be used. The reasons for this are lost in the mists of time
2270 * (or just really crappy memories). Regardless, this is really annoying
2271 * for userspace. So to keep things simple we map _MPLANE buffer types
2272 * to their 'regular' counterparts before calling the driver. And we
2273 * restore it afterwards. This way applications can use either buffer
2274 * type and drivers don't need to check for both.
2276 static int v4l_g_selection(const struct v4l2_ioctl_ops
*ops
,
2277 struct file
*file
, void *fh
, void *arg
)
2279 struct v4l2_selection
*p
= arg
;
2280 u32 old_type
= p
->type
;
2283 if (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2284 p
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2285 else if (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
2286 p
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
2287 ret
= ops
->vidioc_g_selection(file
, fh
, p
);
2292 static int v4l_s_selection(const struct v4l2_ioctl_ops
*ops
,
2293 struct file
*file
, void *fh
, void *arg
)
2295 struct v4l2_selection
*p
= arg
;
2296 u32 old_type
= p
->type
;
2299 if (p
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2300 p
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2301 else if (p
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
2302 p
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
2303 ret
= ops
->vidioc_s_selection(file
, fh
, p
);
2308 static int v4l_g_crop(const struct v4l2_ioctl_ops
*ops
,
2309 struct file
*file
, void *fh
, void *arg
)
2311 struct video_device
*vfd
= video_devdata(file
);
2312 struct v4l2_crop
*p
= arg
;
2313 struct v4l2_selection s
= {
2318 /* simulate capture crop using selection api */
2320 /* crop means compose for output devices */
2321 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
2322 s
.target
= V4L2_SEL_TGT_COMPOSE
;
2324 s
.target
= V4L2_SEL_TGT_CROP
;
2326 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP
, &vfd
->flags
))
2327 s
.target
= s
.target
== V4L2_SEL_TGT_COMPOSE
?
2328 V4L2_SEL_TGT_CROP
: V4L2_SEL_TGT_COMPOSE
;
2330 ret
= v4l_g_selection(ops
, file
, fh
, &s
);
2332 /* copying results to old structure on success */
2338 static int v4l_s_crop(const struct v4l2_ioctl_ops
*ops
,
2339 struct file
*file
, void *fh
, void *arg
)
2341 struct video_device
*vfd
= video_devdata(file
);
2342 struct v4l2_crop
*p
= arg
;
2343 struct v4l2_selection s
= {
2348 /* simulate capture crop using selection api */
2350 /* crop means compose for output devices */
2351 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
2352 s
.target
= V4L2_SEL_TGT_COMPOSE
;
2354 s
.target
= V4L2_SEL_TGT_CROP
;
2356 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP
, &vfd
->flags
))
2357 s
.target
= s
.target
== V4L2_SEL_TGT_COMPOSE
?
2358 V4L2_SEL_TGT_CROP
: V4L2_SEL_TGT_COMPOSE
;
2360 return v4l_s_selection(ops
, file
, fh
, &s
);
2363 static int v4l_cropcap(const struct v4l2_ioctl_ops
*ops
,
2364 struct file
*file
, void *fh
, void *arg
)
2366 struct video_device
*vfd
= video_devdata(file
);
2367 struct v4l2_cropcap
*p
= arg
;
2368 struct v4l2_selection s
= { .type
= p
->type
};
2371 /* setting trivial pixelaspect */
2372 p
->pixelaspect
.numerator
= 1;
2373 p
->pixelaspect
.denominator
= 1;
2375 if (s
.type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
2376 s
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2377 else if (s
.type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
2378 s
.type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
2381 * The determine_valid_ioctls() call already should ensure
2382 * that this can never happen, but just in case...
2384 if (WARN_ON(!ops
->vidioc_g_selection
))
2387 if (ops
->vidioc_g_pixelaspect
)
2388 ret
= ops
->vidioc_g_pixelaspect(file
, fh
, s
.type
,
2392 * Ignore ENOTTY or ENOIOCTLCMD error returns, just use the
2393 * square pixel aspect ratio in that case.
2395 if (ret
&& ret
!= -ENOTTY
&& ret
!= -ENOIOCTLCMD
)
2398 /* Use g_selection() to fill in the bounds and defrect rectangles */
2400 /* obtaining bounds */
2401 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
2402 s
.target
= V4L2_SEL_TGT_COMPOSE_BOUNDS
;
2404 s
.target
= V4L2_SEL_TGT_CROP_BOUNDS
;
2406 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP
, &vfd
->flags
))
2407 s
.target
= s
.target
== V4L2_SEL_TGT_COMPOSE_BOUNDS
?
2408 V4L2_SEL_TGT_CROP_BOUNDS
: V4L2_SEL_TGT_COMPOSE_BOUNDS
;
2410 ret
= v4l_g_selection(ops
, file
, fh
, &s
);
2415 /* obtaining defrect */
2416 if (s
.target
== V4L2_SEL_TGT_COMPOSE_BOUNDS
)
2417 s
.target
= V4L2_SEL_TGT_COMPOSE_DEFAULT
;
2419 s
.target
= V4L2_SEL_TGT_CROP_DEFAULT
;
2421 ret
= v4l_g_selection(ops
, file
, fh
, &s
);
2429 static int v4l_log_status(const struct v4l2_ioctl_ops
*ops
,
2430 struct file
*file
, void *fh
, void *arg
)
2432 struct video_device
*vfd
= video_devdata(file
);
2436 pr_info("%s: ================= START STATUS =================\n",
2437 vfd
->v4l2_dev
->name
);
2438 ret
= ops
->vidioc_log_status(file
, fh
);
2440 pr_info("%s: ================== END STATUS ==================\n",
2441 vfd
->v4l2_dev
->name
);
2445 static int v4l_dbg_g_register(const struct v4l2_ioctl_ops
*ops
,
2446 struct file
*file
, void *fh
, void *arg
)
2448 #ifdef CONFIG_VIDEO_ADV_DEBUG
2449 struct v4l2_dbg_register
*p
= arg
;
2450 struct video_device
*vfd
= video_devdata(file
);
2451 struct v4l2_subdev
*sd
;
2454 if (!capable(CAP_SYS_ADMIN
))
2456 if (p
->match
.type
== V4L2_CHIP_MATCH_SUBDEV
) {
2457 if (vfd
->v4l2_dev
== NULL
)
2459 v4l2_device_for_each_subdev(sd
, vfd
->v4l2_dev
)
2460 if (p
->match
.addr
== idx
++)
2461 return v4l2_subdev_call(sd
, core
, g_register
, p
);
2464 if (ops
->vidioc_g_register
&& p
->match
.type
== V4L2_CHIP_MATCH_BRIDGE
&&
2465 (ops
->vidioc_g_chip_info
|| p
->match
.addr
== 0))
2466 return ops
->vidioc_g_register(file
, fh
, p
);
2473 static int v4l_dbg_s_register(const struct v4l2_ioctl_ops
*ops
,
2474 struct file
*file
, void *fh
, void *arg
)
2476 #ifdef CONFIG_VIDEO_ADV_DEBUG
2477 const struct v4l2_dbg_register
*p
= arg
;
2478 struct video_device
*vfd
= video_devdata(file
);
2479 struct v4l2_subdev
*sd
;
2482 if (!capable(CAP_SYS_ADMIN
))
2484 if (p
->match
.type
== V4L2_CHIP_MATCH_SUBDEV
) {
2485 if (vfd
->v4l2_dev
== NULL
)
2487 v4l2_device_for_each_subdev(sd
, vfd
->v4l2_dev
)
2488 if (p
->match
.addr
== idx
++)
2489 return v4l2_subdev_call(sd
, core
, s_register
, p
);
2492 if (ops
->vidioc_s_register
&& p
->match
.type
== V4L2_CHIP_MATCH_BRIDGE
&&
2493 (ops
->vidioc_g_chip_info
|| p
->match
.addr
== 0))
2494 return ops
->vidioc_s_register(file
, fh
, p
);
2501 static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops
*ops
,
2502 struct file
*file
, void *fh
, void *arg
)
2504 #ifdef CONFIG_VIDEO_ADV_DEBUG
2505 struct video_device
*vfd
= video_devdata(file
);
2506 struct v4l2_dbg_chip_info
*p
= arg
;
2507 struct v4l2_subdev
*sd
;
2510 switch (p
->match
.type
) {
2511 case V4L2_CHIP_MATCH_BRIDGE
:
2512 if (ops
->vidioc_s_register
)
2513 p
->flags
|= V4L2_CHIP_FL_WRITABLE
;
2514 if (ops
->vidioc_g_register
)
2515 p
->flags
|= V4L2_CHIP_FL_READABLE
;
2516 strscpy(p
->name
, vfd
->v4l2_dev
->name
, sizeof(p
->name
));
2517 if (ops
->vidioc_g_chip_info
)
2518 return ops
->vidioc_g_chip_info(file
, fh
, arg
);
2523 case V4L2_CHIP_MATCH_SUBDEV
:
2524 if (vfd
->v4l2_dev
== NULL
)
2526 v4l2_device_for_each_subdev(sd
, vfd
->v4l2_dev
) {
2527 if (p
->match
.addr
!= idx
++)
2529 if (sd
->ops
->core
&& sd
->ops
->core
->s_register
)
2530 p
->flags
|= V4L2_CHIP_FL_WRITABLE
;
2531 if (sd
->ops
->core
&& sd
->ops
->core
->g_register
)
2532 p
->flags
|= V4L2_CHIP_FL_READABLE
;
2533 strscpy(p
->name
, sd
->name
, sizeof(p
->name
));
2544 static int v4l_dqevent(const struct v4l2_ioctl_ops
*ops
,
2545 struct file
*file
, void *fh
, void *arg
)
2547 return v4l2_event_dequeue(fh
, arg
, file
->f_flags
& O_NONBLOCK
);
2550 static int v4l_subscribe_event(const struct v4l2_ioctl_ops
*ops
,
2551 struct file
*file
, void *fh
, void *arg
)
2553 return ops
->vidioc_subscribe_event(fh
, arg
);
2556 static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops
*ops
,
2557 struct file
*file
, void *fh
, void *arg
)
2559 return ops
->vidioc_unsubscribe_event(fh
, arg
);
2562 static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops
*ops
,
2563 struct file
*file
, void *fh
, void *arg
)
2565 struct v4l2_sliced_vbi_cap
*p
= arg
;
2566 int ret
= check_fmt(file
, p
->type
);
2571 /* Clear up to type, everything after type is zeroed already */
2572 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
2574 return ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
2577 static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops
*ops
,
2578 struct file
*file
, void *fh
, void *arg
)
2580 struct video_device
*vfd
= video_devdata(file
);
2581 struct v4l2_frequency_band
*p
= arg
;
2582 enum v4l2_tuner_type type
;
2585 if (vfd
->vfl_type
== VFL_TYPE_SDR
) {
2586 if (p
->type
!= V4L2_TUNER_SDR
&& p
->type
!= V4L2_TUNER_RF
)
2590 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
2591 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
2592 if (type
!= p
->type
)
2595 if (ops
->vidioc_enum_freq_bands
) {
2596 err
= ops
->vidioc_enum_freq_bands(file
, fh
, p
);
2600 if (is_valid_ioctl(vfd
, VIDIOC_G_TUNER
)) {
2601 struct v4l2_tuner t
= {
2608 err
= ops
->vidioc_g_tuner(file
, fh
, &t
);
2611 p
->capability
= t
.capability
| V4L2_TUNER_CAP_FREQ_BANDS
;
2612 p
->rangelow
= t
.rangelow
;
2613 p
->rangehigh
= t
.rangehigh
;
2614 p
->modulation
= (type
== V4L2_TUNER_RADIO
) ?
2615 V4L2_BAND_MODULATION_FM
: V4L2_BAND_MODULATION_VSB
;
2618 if (is_valid_ioctl(vfd
, VIDIOC_G_MODULATOR
)) {
2619 struct v4l2_modulator m
= {
2623 if (type
!= V4L2_TUNER_RADIO
)
2627 err
= ops
->vidioc_g_modulator(file
, fh
, &m
);
2630 p
->capability
= m
.capability
| V4L2_TUNER_CAP_FREQ_BANDS
;
2631 p
->rangelow
= m
.rangelow
;
2632 p
->rangehigh
= m
.rangehigh
;
2633 p
->modulation
= (type
== V4L2_TUNER_RADIO
) ?
2634 V4L2_BAND_MODULATION_FM
: V4L2_BAND_MODULATION_VSB
;
2640 struct v4l2_ioctl_info
{
2643 const char * const name
;
2644 int (*func
)(const struct v4l2_ioctl_ops
*ops
, struct file
*file
,
2646 void (*debug
)(const void *arg
, bool write_only
);
2649 /* This control needs a priority check */
2650 #define INFO_FL_PRIO (1 << 0)
2651 /* This control can be valid if the filehandle passes a control handler. */
2652 #define INFO_FL_CTRL (1 << 1)
2654 #define INFO_FL_QUEUE (1 << 2)
2655 /* Always copy back result, even on error */
2656 #define INFO_FL_ALWAYS_COPY (1 << 3)
2657 /* Zero struct from after the field to the end */
2658 #define INFO_FL_CLEAR(v4l2_struct, field) \
2659 ((offsetof(struct v4l2_struct, field) + \
2660 sizeof_field(struct v4l2_struct, field)) << 16)
2661 #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
2663 #define DEFINE_V4L_STUB_FUNC(_vidioc) \
2664 static int v4l_stub_ ## _vidioc( \
2665 const struct v4l2_ioctl_ops *ops, \
2666 struct file *file, void *fh, void *p) \
2668 return ops->vidioc_ ## _vidioc(file, fh, p); \
2671 #define IOCTL_INFO(_ioctl, _func, _debug, _flags) \
2672 [_IOC_NR(_ioctl)] = { \
2680 DEFINE_V4L_STUB_FUNC(g_fbuf
)
2681 DEFINE_V4L_STUB_FUNC(s_fbuf
)
2682 DEFINE_V4L_STUB_FUNC(expbuf
)
2683 DEFINE_V4L_STUB_FUNC(g_std
)
2684 DEFINE_V4L_STUB_FUNC(g_audio
)
2685 DEFINE_V4L_STUB_FUNC(s_audio
)
2686 DEFINE_V4L_STUB_FUNC(g_input
)
2687 DEFINE_V4L_STUB_FUNC(g_edid
)
2688 DEFINE_V4L_STUB_FUNC(s_edid
)
2689 DEFINE_V4L_STUB_FUNC(g_output
)
2690 DEFINE_V4L_STUB_FUNC(g_audout
)
2691 DEFINE_V4L_STUB_FUNC(s_audout
)
2692 DEFINE_V4L_STUB_FUNC(g_jpegcomp
)
2693 DEFINE_V4L_STUB_FUNC(s_jpegcomp
)
2694 DEFINE_V4L_STUB_FUNC(enumaudio
)
2695 DEFINE_V4L_STUB_FUNC(enumaudout
)
2696 DEFINE_V4L_STUB_FUNC(enum_framesizes
)
2697 DEFINE_V4L_STUB_FUNC(enum_frameintervals
)
2698 DEFINE_V4L_STUB_FUNC(g_enc_index
)
2699 DEFINE_V4L_STUB_FUNC(encoder_cmd
)
2700 DEFINE_V4L_STUB_FUNC(try_encoder_cmd
)
2701 DEFINE_V4L_STUB_FUNC(decoder_cmd
)
2702 DEFINE_V4L_STUB_FUNC(try_decoder_cmd
)
2703 DEFINE_V4L_STUB_FUNC(s_dv_timings
)
2704 DEFINE_V4L_STUB_FUNC(g_dv_timings
)
2705 DEFINE_V4L_STUB_FUNC(enum_dv_timings
)
2706 DEFINE_V4L_STUB_FUNC(query_dv_timings
)
2707 DEFINE_V4L_STUB_FUNC(dv_timings_cap
)
2709 static const struct v4l2_ioctl_info v4l2_ioctls
[] = {
2710 IOCTL_INFO(VIDIOC_QUERYCAP
, v4l_querycap
, v4l_print_querycap
, 0),
2711 IOCTL_INFO(VIDIOC_ENUM_FMT
, v4l_enum_fmt
, v4l_print_fmtdesc
, INFO_FL_CLEAR(v4l2_fmtdesc
, type
)),
2712 IOCTL_INFO(VIDIOC_G_FMT
, v4l_g_fmt
, v4l_print_format
, 0),
2713 IOCTL_INFO(VIDIOC_S_FMT
, v4l_s_fmt
, v4l_print_format
, INFO_FL_PRIO
),
2714 IOCTL_INFO(VIDIOC_REQBUFS
, v4l_reqbufs
, v4l_print_requestbuffers
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2715 IOCTL_INFO(VIDIOC_QUERYBUF
, v4l_querybuf
, v4l_print_buffer
, INFO_FL_QUEUE
| INFO_FL_CLEAR(v4l2_buffer
, length
)),
2716 IOCTL_INFO(VIDIOC_G_FBUF
, v4l_stub_g_fbuf
, v4l_print_framebuffer
, 0),
2717 IOCTL_INFO(VIDIOC_S_FBUF
, v4l_stub_s_fbuf
, v4l_print_framebuffer
, INFO_FL_PRIO
),
2718 IOCTL_INFO(VIDIOC_OVERLAY
, v4l_overlay
, v4l_print_u32
, INFO_FL_PRIO
),
2719 IOCTL_INFO(VIDIOC_QBUF
, v4l_qbuf
, v4l_print_buffer
, INFO_FL_QUEUE
),
2720 IOCTL_INFO(VIDIOC_EXPBUF
, v4l_stub_expbuf
, v4l_print_exportbuffer
, INFO_FL_QUEUE
| INFO_FL_CLEAR(v4l2_exportbuffer
, flags
)),
2721 IOCTL_INFO(VIDIOC_DQBUF
, v4l_dqbuf
, v4l_print_buffer
, INFO_FL_QUEUE
),
2722 IOCTL_INFO(VIDIOC_STREAMON
, v4l_streamon
, v4l_print_buftype
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2723 IOCTL_INFO(VIDIOC_STREAMOFF
, v4l_streamoff
, v4l_print_buftype
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2724 IOCTL_INFO(VIDIOC_G_PARM
, v4l_g_parm
, v4l_print_streamparm
, INFO_FL_CLEAR(v4l2_streamparm
, type
)),
2725 IOCTL_INFO(VIDIOC_S_PARM
, v4l_s_parm
, v4l_print_streamparm
, INFO_FL_PRIO
),
2726 IOCTL_INFO(VIDIOC_G_STD
, v4l_stub_g_std
, v4l_print_std
, 0),
2727 IOCTL_INFO(VIDIOC_S_STD
, v4l_s_std
, v4l_print_std
, INFO_FL_PRIO
),
2728 IOCTL_INFO(VIDIOC_ENUMSTD
, v4l_enumstd
, v4l_print_standard
, INFO_FL_CLEAR(v4l2_standard
, index
)),
2729 IOCTL_INFO(VIDIOC_ENUMINPUT
, v4l_enuminput
, v4l_print_enuminput
, INFO_FL_CLEAR(v4l2_input
, index
)),
2730 IOCTL_INFO(VIDIOC_G_CTRL
, v4l_g_ctrl
, v4l_print_control
, INFO_FL_CTRL
| INFO_FL_CLEAR(v4l2_control
, id
)),
2731 IOCTL_INFO(VIDIOC_S_CTRL
, v4l_s_ctrl
, v4l_print_control
, INFO_FL_PRIO
| INFO_FL_CTRL
),
2732 IOCTL_INFO(VIDIOC_G_TUNER
, v4l_g_tuner
, v4l_print_tuner
, INFO_FL_CLEAR(v4l2_tuner
, index
)),
2733 IOCTL_INFO(VIDIOC_S_TUNER
, v4l_s_tuner
, v4l_print_tuner
, INFO_FL_PRIO
),
2734 IOCTL_INFO(VIDIOC_G_AUDIO
, v4l_stub_g_audio
, v4l_print_audio
, 0),
2735 IOCTL_INFO(VIDIOC_S_AUDIO
, v4l_stub_s_audio
, v4l_print_audio
, INFO_FL_PRIO
),
2736 IOCTL_INFO(VIDIOC_QUERYCTRL
, v4l_queryctrl
, v4l_print_queryctrl
, INFO_FL_CTRL
| INFO_FL_CLEAR(v4l2_queryctrl
, id
)),
2737 IOCTL_INFO(VIDIOC_QUERYMENU
, v4l_querymenu
, v4l_print_querymenu
, INFO_FL_CTRL
| INFO_FL_CLEAR(v4l2_querymenu
, index
)),
2738 IOCTL_INFO(VIDIOC_G_INPUT
, v4l_stub_g_input
, v4l_print_u32
, 0),
2739 IOCTL_INFO(VIDIOC_S_INPUT
, v4l_s_input
, v4l_print_u32
, INFO_FL_PRIO
),
2740 IOCTL_INFO(VIDIOC_G_EDID
, v4l_stub_g_edid
, v4l_print_edid
, INFO_FL_ALWAYS_COPY
),
2741 IOCTL_INFO(VIDIOC_S_EDID
, v4l_stub_s_edid
, v4l_print_edid
, INFO_FL_PRIO
| INFO_FL_ALWAYS_COPY
),
2742 IOCTL_INFO(VIDIOC_G_OUTPUT
, v4l_stub_g_output
, v4l_print_u32
, 0),
2743 IOCTL_INFO(VIDIOC_S_OUTPUT
, v4l_s_output
, v4l_print_u32
, INFO_FL_PRIO
),
2744 IOCTL_INFO(VIDIOC_ENUMOUTPUT
, v4l_enumoutput
, v4l_print_enumoutput
, INFO_FL_CLEAR(v4l2_output
, index
)),
2745 IOCTL_INFO(VIDIOC_G_AUDOUT
, v4l_stub_g_audout
, v4l_print_audioout
, 0),
2746 IOCTL_INFO(VIDIOC_S_AUDOUT
, v4l_stub_s_audout
, v4l_print_audioout
, INFO_FL_PRIO
),
2747 IOCTL_INFO(VIDIOC_G_MODULATOR
, v4l_g_modulator
, v4l_print_modulator
, INFO_FL_CLEAR(v4l2_modulator
, index
)),
2748 IOCTL_INFO(VIDIOC_S_MODULATOR
, v4l_s_modulator
, v4l_print_modulator
, INFO_FL_PRIO
),
2749 IOCTL_INFO(VIDIOC_G_FREQUENCY
, v4l_g_frequency
, v4l_print_frequency
, INFO_FL_CLEAR(v4l2_frequency
, tuner
)),
2750 IOCTL_INFO(VIDIOC_S_FREQUENCY
, v4l_s_frequency
, v4l_print_frequency
, INFO_FL_PRIO
),
2751 IOCTL_INFO(VIDIOC_CROPCAP
, v4l_cropcap
, v4l_print_cropcap
, INFO_FL_CLEAR(v4l2_cropcap
, type
)),
2752 IOCTL_INFO(VIDIOC_G_CROP
, v4l_g_crop
, v4l_print_crop
, INFO_FL_CLEAR(v4l2_crop
, type
)),
2753 IOCTL_INFO(VIDIOC_S_CROP
, v4l_s_crop
, v4l_print_crop
, INFO_FL_PRIO
),
2754 IOCTL_INFO(VIDIOC_G_SELECTION
, v4l_g_selection
, v4l_print_selection
, INFO_FL_CLEAR(v4l2_selection
, r
)),
2755 IOCTL_INFO(VIDIOC_S_SELECTION
, v4l_s_selection
, v4l_print_selection
, INFO_FL_PRIO
| INFO_FL_CLEAR(v4l2_selection
, r
)),
2756 IOCTL_INFO(VIDIOC_G_JPEGCOMP
, v4l_stub_g_jpegcomp
, v4l_print_jpegcompression
, 0),
2757 IOCTL_INFO(VIDIOC_S_JPEGCOMP
, v4l_stub_s_jpegcomp
, v4l_print_jpegcompression
, INFO_FL_PRIO
),
2758 IOCTL_INFO(VIDIOC_QUERYSTD
, v4l_querystd
, v4l_print_std
, 0),
2759 IOCTL_INFO(VIDIOC_TRY_FMT
, v4l_try_fmt
, v4l_print_format
, 0),
2760 IOCTL_INFO(VIDIOC_ENUMAUDIO
, v4l_stub_enumaudio
, v4l_print_audio
, INFO_FL_CLEAR(v4l2_audio
, index
)),
2761 IOCTL_INFO(VIDIOC_ENUMAUDOUT
, v4l_stub_enumaudout
, v4l_print_audioout
, INFO_FL_CLEAR(v4l2_audioout
, index
)),
2762 IOCTL_INFO(VIDIOC_G_PRIORITY
, v4l_g_priority
, v4l_print_u32
, 0),
2763 IOCTL_INFO(VIDIOC_S_PRIORITY
, v4l_s_priority
, v4l_print_u32
, INFO_FL_PRIO
),
2764 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
)),
2765 IOCTL_INFO(VIDIOC_LOG_STATUS
, v4l_log_status
, v4l_print_newline
, 0),
2766 IOCTL_INFO(VIDIOC_G_EXT_CTRLS
, v4l_g_ext_ctrls
, v4l_print_ext_controls
, INFO_FL_CTRL
),
2767 IOCTL_INFO(VIDIOC_S_EXT_CTRLS
, v4l_s_ext_ctrls
, v4l_print_ext_controls
, INFO_FL_PRIO
| INFO_FL_CTRL
),
2768 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS
, v4l_try_ext_ctrls
, v4l_print_ext_controls
, INFO_FL_CTRL
),
2769 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES
, v4l_stub_enum_framesizes
, v4l_print_frmsizeenum
, INFO_FL_CLEAR(v4l2_frmsizeenum
, pixel_format
)),
2770 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS
, v4l_stub_enum_frameintervals
, v4l_print_frmivalenum
, INFO_FL_CLEAR(v4l2_frmivalenum
, height
)),
2771 IOCTL_INFO(VIDIOC_G_ENC_INDEX
, v4l_stub_g_enc_index
, v4l_print_enc_idx
, 0),
2772 IOCTL_INFO(VIDIOC_ENCODER_CMD
, v4l_stub_encoder_cmd
, v4l_print_encoder_cmd
, INFO_FL_PRIO
| INFO_FL_CLEAR(v4l2_encoder_cmd
, flags
)),
2773 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD
, v4l_stub_try_encoder_cmd
, v4l_print_encoder_cmd
, INFO_FL_CLEAR(v4l2_encoder_cmd
, flags
)),
2774 IOCTL_INFO(VIDIOC_DECODER_CMD
, v4l_stub_decoder_cmd
, v4l_print_decoder_cmd
, INFO_FL_PRIO
),
2775 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD
, v4l_stub_try_decoder_cmd
, v4l_print_decoder_cmd
, 0),
2776 IOCTL_INFO(VIDIOC_DBG_S_REGISTER
, v4l_dbg_s_register
, v4l_print_dbg_register
, 0),
2777 IOCTL_INFO(VIDIOC_DBG_G_REGISTER
, v4l_dbg_g_register
, v4l_print_dbg_register
, 0),
2778 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK
, v4l_s_hw_freq_seek
, v4l_print_hw_freq_seek
, INFO_FL_PRIO
),
2779 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
)),
2780 IOCTL_INFO(VIDIOC_G_DV_TIMINGS
, v4l_stub_g_dv_timings
, v4l_print_dv_timings
, 0),
2781 IOCTL_INFO(VIDIOC_DQEVENT
, v4l_dqevent
, v4l_print_event
, 0),
2782 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT
, v4l_subscribe_event
, v4l_print_event_subscription
, 0),
2783 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT
, v4l_unsubscribe_event
, v4l_print_event_subscription
, 0),
2784 IOCTL_INFO(VIDIOC_CREATE_BUFS
, v4l_create_bufs
, v4l_print_create_buffers
, INFO_FL_PRIO
| INFO_FL_QUEUE
),
2785 IOCTL_INFO(VIDIOC_PREPARE_BUF
, v4l_prepare_buf
, v4l_print_buffer
, INFO_FL_QUEUE
),
2786 IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS
, v4l_stub_enum_dv_timings
, v4l_print_enum_dv_timings
, INFO_FL_CLEAR(v4l2_enum_dv_timings
, pad
)),
2787 IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS
, v4l_stub_query_dv_timings
, v4l_print_dv_timings
, INFO_FL_ALWAYS_COPY
),
2788 IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP
, v4l_stub_dv_timings_cap
, v4l_print_dv_timings_cap
, INFO_FL_CLEAR(v4l2_dv_timings_cap
, pad
)),
2789 IOCTL_INFO(VIDIOC_ENUM_FREQ_BANDS
, v4l_enum_freq_bands
, v4l_print_freq_band
, 0),
2790 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
)),
2791 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
)),
2793 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
2795 static bool v4l2_is_known_ioctl(unsigned int cmd
)
2797 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
)
2799 return v4l2_ioctls
[_IOC_NR(cmd
)].ioctl
== cmd
;
2802 static struct mutex
*v4l2_ioctl_get_lock(struct video_device
*vdev
,
2803 struct v4l2_fh
*vfh
, unsigned int cmd
,
2806 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
)
2808 #if IS_ENABLED(CONFIG_V4L2_MEM2MEM_DEV)
2809 if (vfh
&& vfh
->m2m_ctx
&&
2810 (v4l2_ioctls
[_IOC_NR(cmd
)].flags
& INFO_FL_QUEUE
)) {
2811 if (vfh
->m2m_ctx
->q_lock
)
2812 return vfh
->m2m_ctx
->q_lock
;
2815 if (vdev
->queue
&& vdev
->queue
->lock
&&
2816 (v4l2_ioctls
[_IOC_NR(cmd
)].flags
& INFO_FL_QUEUE
))
2817 return vdev
->queue
->lock
;
2821 /* Common ioctl debug function. This function can be used by
2822 external ioctl messages as well as internal V4L ioctl */
2823 void v4l_printk_ioctl(const char *prefix
, unsigned int cmd
)
2825 const char *dir
, *type
;
2828 printk(KERN_DEBUG
"%s: ", prefix
);
2830 switch (_IOC_TYPE(cmd
)) {
2835 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
2839 pr_cont("%s", v4l2_ioctls
[_IOC_NR(cmd
)].name
);
2846 switch (_IOC_DIR(cmd
)) {
2847 case _IOC_NONE
: dir
= "--"; break;
2848 case _IOC_READ
: dir
= "r-"; break;
2849 case _IOC_WRITE
: dir
= "-w"; break;
2850 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
2851 default: dir
= "*ERR*"; break;
2853 pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
2854 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
2856 EXPORT_SYMBOL(v4l_printk_ioctl
);
2858 static long __video_do_ioctl(struct file
*file
,
2859 unsigned int cmd
, void *arg
)
2861 struct video_device
*vfd
= video_devdata(file
);
2862 struct mutex
*req_queue_lock
= NULL
;
2863 struct mutex
*lock
; /* ioctl serialization mutex */
2864 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
2865 bool write_only
= false;
2866 struct v4l2_ioctl_info default_info
;
2867 const struct v4l2_ioctl_info
*info
;
2868 void *fh
= file
->private_data
;
2869 struct v4l2_fh
*vfh
= NULL
;
2870 int dev_debug
= vfd
->dev_debug
;
2874 pr_warn("%s: has no ioctl_ops.\n",
2875 video_device_node_name(vfd
));
2879 if (test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
))
2880 vfh
= file
->private_data
;
2883 * We need to serialize streamon/off with queueing new requests.
2884 * These ioctls may trigger the cancellation of a streaming
2885 * operation, and that should not be mixed with queueing a new
2886 * request at the same time.
2888 if (v4l2_device_supports_requests(vfd
->v4l2_dev
) &&
2889 (cmd
== VIDIOC_STREAMON
|| cmd
== VIDIOC_STREAMOFF
)) {
2890 req_queue_lock
= &vfd
->v4l2_dev
->mdev
->req_queue_mutex
;
2892 if (mutex_lock_interruptible(req_queue_lock
))
2893 return -ERESTARTSYS
;
2896 lock
= v4l2_ioctl_get_lock(vfd
, vfh
, cmd
, arg
);
2898 if (lock
&& mutex_lock_interruptible(lock
)) {
2900 mutex_unlock(req_queue_lock
);
2901 return -ERESTARTSYS
;
2904 if (!video_is_registered(vfd
)) {
2909 if (v4l2_is_known_ioctl(cmd
)) {
2910 info
= &v4l2_ioctls
[_IOC_NR(cmd
)];
2912 if (!test_bit(_IOC_NR(cmd
), vfd
->valid_ioctls
) &&
2913 !((info
->flags
& INFO_FL_CTRL
) && vfh
&& vfh
->ctrl_handler
))
2916 if (vfh
&& (info
->flags
& INFO_FL_PRIO
)) {
2917 ret
= v4l2_prio_check(vfd
->prio
, vfh
->prio
);
2922 default_info
.ioctl
= cmd
;
2923 default_info
.flags
= 0;
2924 default_info
.debug
= v4l_print_default
;
2925 info
= &default_info
;
2928 write_only
= _IOC_DIR(cmd
) == _IOC_WRITE
;
2929 if (info
!= &default_info
) {
2930 ret
= info
->func(ops
, file
, fh
, arg
);
2931 } else if (!ops
->vidioc_default
) {
2934 ret
= ops
->vidioc_default(file
, fh
,
2935 vfh
? v4l2_prio_check(vfd
->prio
, vfh
->prio
) >= 0 : 0,
2940 if (dev_debug
& (V4L2_DEV_DEBUG_IOCTL
| V4L2_DEV_DEBUG_IOCTL_ARG
)) {
2941 if (!(dev_debug
& V4L2_DEV_DEBUG_STREAMING
) &&
2942 (cmd
== VIDIOC_QBUF
|| cmd
== VIDIOC_DQBUF
))
2945 v4l_printk_ioctl(video_device_node_name(vfd
), cmd
);
2947 pr_cont(": error %ld", ret
);
2948 if (!(dev_debug
& V4L2_DEV_DEBUG_IOCTL_ARG
))
2950 else if (_IOC_DIR(cmd
) == _IOC_NONE
)
2951 info
->debug(arg
, write_only
);
2954 info
->debug(arg
, write_only
);
2962 mutex_unlock(req_queue_lock
);
2966 static int check_array_args(unsigned int cmd
, void *parg
, size_t *array_size
,
2967 void __user
**user_ptr
, void ***kernel_ptr
)
2972 case VIDIOC_PREPARE_BUF
:
2973 case VIDIOC_QUERYBUF
:
2975 case VIDIOC_DQBUF
: {
2976 struct v4l2_buffer
*buf
= parg
;
2978 if (V4L2_TYPE_IS_MULTIPLANAR(buf
->type
) && buf
->length
> 0) {
2979 if (buf
->length
> VIDEO_MAX_PLANES
) {
2983 *user_ptr
= (void __user
*)buf
->m
.planes
;
2984 *kernel_ptr
= (void **)&buf
->m
.planes
;
2985 *array_size
= sizeof(struct v4l2_plane
) * buf
->length
;
2992 case VIDIOC_S_EDID
: {
2993 struct v4l2_edid
*edid
= parg
;
2996 if (edid
->blocks
> 256) {
3000 *user_ptr
= (void __user
*)edid
->edid
;
3001 *kernel_ptr
= (void **)&edid
->edid
;
3002 *array_size
= edid
->blocks
* 128;
3008 case VIDIOC_S_EXT_CTRLS
:
3009 case VIDIOC_G_EXT_CTRLS
:
3010 case VIDIOC_TRY_EXT_CTRLS
: {
3011 struct v4l2_ext_controls
*ctrls
= parg
;
3013 if (ctrls
->count
!= 0) {
3014 if (ctrls
->count
> V4L2_CID_MAX_CTRLS
) {
3018 *user_ptr
= (void __user
*)ctrls
->controls
;
3019 *kernel_ptr
= (void **)&ctrls
->controls
;
3020 *array_size
= sizeof(struct v4l2_ext_control
)
3031 static unsigned int video_translate_cmd(unsigned int cmd
)
3034 #ifdef CONFIG_COMPAT_32BIT_TIME
3035 case VIDIOC_DQEVENT_TIME32
:
3036 return VIDIOC_DQEVENT
;
3037 case VIDIOC_QUERYBUF_TIME32
:
3038 return VIDIOC_QUERYBUF
;
3039 case VIDIOC_QBUF_TIME32
:
3041 case VIDIOC_DQBUF_TIME32
:
3042 return VIDIOC_DQBUF
;
3043 case VIDIOC_PREPARE_BUF_TIME32
:
3044 return VIDIOC_PREPARE_BUF
;
3051 static int video_get_user(void __user
*arg
, void *parg
, unsigned int cmd
,
3054 unsigned int n
= _IOC_SIZE(cmd
);
3056 if (!(_IOC_DIR(cmd
) & _IOC_WRITE
)) {
3057 /* read-only ioctl */
3063 #ifdef CONFIG_COMPAT_32BIT_TIME
3064 case VIDIOC_QUERYBUF_TIME32
:
3065 case VIDIOC_QBUF_TIME32
:
3066 case VIDIOC_DQBUF_TIME32
:
3067 case VIDIOC_PREPARE_BUF_TIME32
: {
3068 struct v4l2_buffer_time32 vb32
;
3069 struct v4l2_buffer
*vb
= parg
;
3071 if (copy_from_user(&vb32
, arg
, sizeof(vb32
)))
3074 *vb
= (struct v4l2_buffer
) {
3075 .index
= vb32
.index
,
3077 .bytesused
= vb32
.bytesused
,
3078 .flags
= vb32
.flags
,
3079 .field
= vb32
.field
,
3080 .timestamp
.tv_sec
= vb32
.timestamp
.tv_sec
,
3081 .timestamp
.tv_usec
= vb32
.timestamp
.tv_usec
,
3082 .timecode
= vb32
.timecode
,
3083 .sequence
= vb32
.sequence
,
3084 .memory
= vb32
.memory
,
3085 .m
.userptr
= vb32
.m
.userptr
,
3086 .length
= vb32
.length
,
3087 .request_fd
= vb32
.request_fd
,
3090 if (cmd
== VIDIOC_QUERYBUF_TIME32
)
3098 * In some cases, only a few fields are used as input,
3099 * i.e. when the app sets "index" and then the driver
3100 * fills in the rest of the structure for the thing
3101 * with that index. We only need to copy up the first
3104 if (v4l2_is_known_ioctl(cmd
)) {
3105 u32 flags
= v4l2_ioctls
[_IOC_NR(cmd
)].flags
;
3107 if (flags
& INFO_FL_CLEAR_MASK
)
3108 n
= (flags
& INFO_FL_CLEAR_MASK
) >> 16;
3109 *always_copy
= flags
& INFO_FL_ALWAYS_COPY
;
3112 if (copy_from_user(parg
, (void __user
*)arg
, n
))
3115 /* zero out anything we don't copy from userspace */
3116 if (n
< _IOC_SIZE(cmd
))
3117 memset((u8
*)parg
+ n
, 0, _IOC_SIZE(cmd
) - n
);
3124 static int video_put_user(void __user
*arg
, void *parg
, unsigned int cmd
)
3126 if (!(_IOC_DIR(cmd
) & _IOC_READ
))
3130 #ifdef CONFIG_COMPAT_32BIT_TIME
3131 case VIDIOC_DQEVENT_TIME32
: {
3132 struct v4l2_event
*ev
= parg
;
3133 struct v4l2_event_time32 ev32
= {
3135 .pending
= ev
->pending
,
3136 .sequence
= ev
->sequence
,
3137 .timestamp
.tv_sec
= ev
->timestamp
.tv_sec
,
3138 .timestamp
.tv_nsec
= ev
->timestamp
.tv_nsec
,
3142 memcpy(&ev32
.u
, &ev
->u
, sizeof(ev
->u
));
3143 memcpy(&ev32
.reserved
, &ev
->reserved
, sizeof(ev
->reserved
));
3145 if (copy_to_user(arg
, &ev32
, sizeof(ev32
)))
3149 case VIDIOC_QUERYBUF_TIME32
:
3150 case VIDIOC_QBUF_TIME32
:
3151 case VIDIOC_DQBUF_TIME32
:
3152 case VIDIOC_PREPARE_BUF_TIME32
: {
3153 struct v4l2_buffer
*vb
= parg
;
3154 struct v4l2_buffer_time32 vb32
= {
3157 .bytesused
= vb
->bytesused
,
3160 .timestamp
.tv_sec
= vb
->timestamp
.tv_sec
,
3161 .timestamp
.tv_usec
= vb
->timestamp
.tv_usec
,
3162 .timecode
= vb
->timecode
,
3163 .sequence
= vb
->sequence
,
3164 .memory
= vb
->memory
,
3165 .m
.userptr
= vb
->m
.userptr
,
3166 .length
= vb
->length
,
3167 .request_fd
= vb
->request_fd
,
3170 if (copy_to_user(arg
, &vb32
, sizeof(vb32
)))
3176 /* Copy results into user buffer */
3177 if (copy_to_user(arg
, parg
, _IOC_SIZE(cmd
)))
3186 video_usercopy(struct file
*file
, unsigned int orig_cmd
, unsigned long arg
,
3191 void *parg
= (void *)arg
;
3193 bool has_array_args
;
3194 bool always_copy
= false;
3195 size_t array_size
= 0;
3196 void __user
*user_ptr
= NULL
;
3197 void **kernel_ptr
= NULL
;
3198 unsigned int cmd
= video_translate_cmd(orig_cmd
);
3199 const size_t ioc_size
= _IOC_SIZE(cmd
);
3201 /* Copy arguments into temp kernel buffer */
3202 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
3203 if (ioc_size
<= sizeof(sbuf
)) {
3206 /* too big to allocate from stack */
3207 mbuf
= kvmalloc(ioc_size
, GFP_KERNEL
);
3213 err
= video_get_user((void __user
*)arg
, parg
, orig_cmd
,
3219 err
= check_array_args(cmd
, parg
, &array_size
, &user_ptr
, &kernel_ptr
);
3222 has_array_args
= err
;
3224 if (has_array_args
) {
3226 * When adding new types of array args, make sure that the
3227 * parent argument to ioctl (which contains the pointer to the
3228 * array) fits into sbuf (so that mbuf will still remain
3229 * unused up to here).
3231 mbuf
= kvmalloc(array_size
, GFP_KERNEL
);
3234 goto out_array_args
;
3236 if (copy_from_user(mbuf
, user_ptr
, array_size
))
3237 goto out_array_args
;
3242 err
= func(file
, cmd
, parg
);
3243 if (err
== -ENOTTY
|| err
== -ENOIOCTLCMD
) {
3249 if (cmd
== VIDIOC_DQBUF
)
3250 trace_v4l2_dqbuf(video_devdata(file
)->minor
, parg
);
3251 else if (cmd
== VIDIOC_QBUF
)
3252 trace_v4l2_qbuf(video_devdata(file
)->minor
, parg
);
3255 if (has_array_args
) {
3256 *kernel_ptr
= (void __force
*)user_ptr
;
3257 if (copy_to_user(user_ptr
, mbuf
, array_size
))
3259 goto out_array_args
;
3262 * Some ioctls can return an error, but still have valid
3263 * results that must be returned.
3265 if (err
< 0 && !always_copy
)
3269 if (video_put_user((void __user
*)arg
, parg
, orig_cmd
))
3276 long video_ioctl2(struct file
*file
,
3277 unsigned int cmd
, unsigned long arg
)
3279 return video_usercopy(file
, cmd
, arg
, __video_do_ioctl
);
3281 EXPORT_SYMBOL(video_ioctl2
);