2 * Video capture interface for Linux version 2
4 * A generic framework to process V4L2 ioctl commands.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
12 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/version.h>
21 #include <linux/videodev2.h>
23 #include <media/v4l2-common.h>
24 #include <media/v4l2-ioctl.h>
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-fh.h>
27 #include <media/v4l2-event.h>
28 #include <media/v4l2-device.h>
29 #include <media/v4l2-chip-ident.h>
31 #define dbgarg(cmd, fmt, arg...) \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
40 #define dbgarg2(fmt, arg...) \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
46 #define dbgarg3(fmt, arg...) \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
52 /* Zero out the end of the struct pointed to by p. Everything after, but
53 * not including, the specified field is cleared. */
54 #define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
63 static const struct std_descr standards[] = {
64 { V4L2_STD_NTSC, "NTSC" },
65 { V4L2_STD_NTSC_M, "NTSC-M" },
66 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
67 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
68 { V4L2_STD_NTSC_443, "NTSC-443" },
69 { V4L2_STD_PAL, "PAL" },
70 { V4L2_STD_PAL_BG, "PAL-BG" },
71 { V4L2_STD_PAL_B, "PAL-B" },
72 { V4L2_STD_PAL_B1, "PAL-B1" },
73 { V4L2_STD_PAL_G, "PAL-G" },
74 { V4L2_STD_PAL_H, "PAL-H" },
75 { V4L2_STD_PAL_I, "PAL-I" },
76 { V4L2_STD_PAL_DK, "PAL-DK" },
77 { V4L2_STD_PAL_D, "PAL-D" },
78 { V4L2_STD_PAL_D1, "PAL-D1" },
79 { V4L2_STD_PAL_K, "PAL-K" },
80 { V4L2_STD_PAL_M, "PAL-M" },
81 { V4L2_STD_PAL_N, "PAL-N" },
82 { V4L2_STD_PAL_Nc, "PAL-Nc" },
83 { V4L2_STD_PAL_60, "PAL-60" },
84 { V4L2_STD_SECAM, "SECAM" },
85 { V4L2_STD_SECAM_B, "SECAM-B" },
86 { V4L2_STD_SECAM_G, "SECAM-G" },
87 { V4L2_STD_SECAM_H, "SECAM-H" },
88 { V4L2_STD_SECAM_DK, "SECAM-DK" },
89 { V4L2_STD_SECAM_D, "SECAM-D" },
90 { V4L2_STD_SECAM_K, "SECAM-K" },
91 { V4L2_STD_SECAM_K1, "SECAM-K1" },
92 { V4L2_STD_SECAM_L, "SECAM-L" },
93 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
97 /* video4linux standard ID conversion to standard name
99 const char *v4l2_norm_to_name(v4l2_std_id id)
104 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
105 64 bit comparations. So, on that architecture, with some gcc
106 variants, compilation fails. Currently, the max value is 30bit wide.
110 for (i = 0; standards[i].std; i++)
111 if (myid == standards[i].std)
113 return standards[i].descr;
115 EXPORT_SYMBOL(v4l2_norm_to_name);
117 /* Returns frame period for the given standard */
118 void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
120 if (id & V4L2_STD_525_60) {
121 frameperiod->numerator = 1001;
122 frameperiod->denominator = 30000;
124 frameperiod->numerator = 1;
125 frameperiod->denominator = 25;
128 EXPORT_SYMBOL(v4l2_video_std_frame_period);
130 /* Fill in the fields of a v4l2_standard structure according to the
131 'id' and 'transmission' parameters. Returns negative on error. */
132 int v4l2_video_std_construct(struct v4l2_standard *vs,
133 int id, const char *name)
136 v4l2_video_std_frame_period(id, &vs->frameperiod);
137 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
138 strlcpy(vs->name, name, sizeof(vs->name));
141 EXPORT_SYMBOL(v4l2_video_std_construct);
143 /* ----------------------------------------------------------------- */
144 /* some arrays for pretty-printing debug messages of enum types */
146 const char *v4l2_field_names[] = {
147 [V4L2_FIELD_ANY] = "any",
148 [V4L2_FIELD_NONE] = "none",
149 [V4L2_FIELD_TOP] = "top",
150 [V4L2_FIELD_BOTTOM] = "bottom",
151 [V4L2_FIELD_INTERLACED] = "interlaced",
152 [V4L2_FIELD_SEQ_TB] = "seq-tb",
153 [V4L2_FIELD_SEQ_BT] = "seq-bt",
154 [V4L2_FIELD_ALTERNATE] = "alternate",
155 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
156 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
158 EXPORT_SYMBOL(v4l2_field_names);
160 const char *v4l2_type_names[] = {
161 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
162 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
163 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
164 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
165 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
166 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
167 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
168 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
169 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
170 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
172 EXPORT_SYMBOL(v4l2_type_names);
174 static const char *v4l2_memory_names[] = {
175 [V4L2_MEMORY_MMAP] = "mmap",
176 [V4L2_MEMORY_USERPTR] = "userptr",
177 [V4L2_MEMORY_OVERLAY] = "overlay",
180 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
183 /* ------------------------------------------------------------------ */
184 /* debug help functions */
186 static void v4l_print_querycap(const void *arg, bool write_only)
188 const struct v4l2_capability *p = arg;
190 pr_cont("driver=%s, card=%s, bus=%s, version=0x%08x, "
191 "capabilities=0x%08x, device_caps=0x%08x\n",
192 p->driver, p->card, p->bus_info,
193 p->version, p->capabilities, p->device_caps);
196 static void v4l_print_enuminput(const void *arg, bool write_only)
198 const struct v4l2_input *p = arg;
200 pr_cont("index=%u, name=%s, type=%u, audioset=0x%x, tuner=%u, "
201 "std=0x%08Lx, status=0x%x, capabilities=0x%x\n",
202 p->index, p->name, p->type, p->audioset, p->tuner,
203 (unsigned long long)p->std, p->status, p->capabilities);
206 static void v4l_print_enumoutput(const void *arg, bool write_only)
208 const struct v4l2_output *p = arg;
210 pr_cont("index=%u, name=%s, type=%u, audioset=0x%x, "
211 "modulator=%u, std=0x%08Lx, capabilities=0x%x\n",
212 p->index, p->name, p->type, p->audioset, p->modulator,
213 (unsigned long long)p->std, p->capabilities);
216 static void v4l_print_audio(const void *arg, bool write_only)
218 const struct v4l2_audio *p = arg;
221 pr_cont("index=%u, mode=0x%x\n", p->index, p->mode);
223 pr_cont("index=%u, name=%s, capability=0x%x, mode=0x%x\n",
224 p->index, p->name, p->capability, p->mode);
227 static void v4l_print_audioout(const void *arg, bool write_only)
229 const struct v4l2_audioout *p = arg;
232 pr_cont("index=%u\n", p->index);
234 pr_cont("index=%u, name=%s, capability=0x%x, mode=0x%x\n",
235 p->index, p->name, p->capability, p->mode);
238 static void v4l_print_fmtdesc(const void *arg, bool write_only)
240 const struct v4l2_fmtdesc *p = arg;
242 pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%s'\n",
243 p->index, prt_names(p->type, v4l2_type_names),
244 p->flags, (p->pixelformat & 0xff),
245 (p->pixelformat >> 8) & 0xff,
246 (p->pixelformat >> 16) & 0xff,
247 (p->pixelformat >> 24) & 0xff,
251 static void v4l_print_format(const void *arg, bool write_only)
253 const struct v4l2_format *p = arg;
254 const struct v4l2_pix_format *pix;
255 const struct v4l2_pix_format_mplane *mp;
256 const struct v4l2_vbi_format *vbi;
257 const struct v4l2_sliced_vbi_format *sliced;
258 const struct v4l2_window *win;
259 const struct v4l2_clip *clip;
262 pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
264 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
265 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
267 pr_cont(", width=%u, height=%u, "
268 "pixelformat=%c%c%c%c, field=%s, "
269 "bytesperline=%u sizeimage=%u, colorspace=%d\n",
270 pix->width, pix->height,
271 (pix->pixelformat & 0xff),
272 (pix->pixelformat >> 8) & 0xff,
273 (pix->pixelformat >> 16) & 0xff,
274 (pix->pixelformat >> 24) & 0xff,
275 prt_names(pix->field, v4l2_field_names),
276 pix->bytesperline, pix->sizeimage,
279 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
280 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
282 pr_cont(", width=%u, height=%u, "
283 "format=%c%c%c%c, field=%s, "
284 "colorspace=%d, num_planes=%u\n",
285 mp->width, mp->height,
286 (mp->pixelformat & 0xff),
287 (mp->pixelformat >> 8) & 0xff,
288 (mp->pixelformat >> 16) & 0xff,
289 (mp->pixelformat >> 24) & 0xff,
290 prt_names(mp->field, v4l2_field_names),
291 mp->colorspace, mp->num_planes);
292 for (i = 0; i < mp->num_planes; i++)
293 printk(KERN_DEBUG "plane %u: bytesperline=%u sizeimage=%u\n", i,
294 mp->plane_fmt[i].bytesperline,
295 mp->plane_fmt[i].sizeimage);
297 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
298 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
300 pr_cont(", wxh=%dx%d, x,y=%d,%d, field=%s, "
301 "chromakey=0x%08x, bitmap=%p, "
302 "global_alpha=0x%02x\n",
303 win->w.width, win->w.height,
304 win->w.left, win->w.top,
305 prt_names(win->field, v4l2_field_names),
306 win->chromakey, win->bitmap, win->global_alpha);
308 for (i = 0; i < win->clipcount; i++) {
309 printk(KERN_DEBUG "clip %u: wxh=%dx%d, x,y=%d,%d\n",
310 i, clip->c.width, clip->c.height,
311 clip->c.left, clip->c.top);
315 case V4L2_BUF_TYPE_VBI_CAPTURE:
316 case V4L2_BUF_TYPE_VBI_OUTPUT:
318 pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, "
319 "sample_format=%c%c%c%c, start=%u,%u, count=%u,%u\n",
320 vbi->sampling_rate, vbi->offset,
321 vbi->samples_per_line,
322 (vbi->sample_format & 0xff),
323 (vbi->sample_format >> 8) & 0xff,
324 (vbi->sample_format >> 16) & 0xff,
325 (vbi->sample_format >> 24) & 0xff,
326 vbi->start[0], vbi->start[1],
327 vbi->count[0], vbi->count[1]);
329 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
330 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
331 sliced = &p->fmt.sliced;
332 pr_cont(", service_set=0x%08x, io_size=%d\n",
333 sliced->service_set, sliced->io_size);
334 for (i = 0; i < 24; i++)
335 printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i,
336 sliced->service_lines[0][i],
337 sliced->service_lines[1][i]);
339 case V4L2_BUF_TYPE_PRIVATE:
345 static void v4l_print_framebuffer(const void *arg, bool write_only)
347 const struct v4l2_framebuffer *p = arg;
349 pr_cont("capability=0x%x, flags=0x%x, base=0x%p, width=%u, "
350 "height=%u, pixelformat=%c%c%c%c, "
351 "bytesperline=%u sizeimage=%u, colorspace=%d\n",
352 p->capability, p->flags, p->base,
353 p->fmt.width, p->fmt.height,
354 (p->fmt.pixelformat & 0xff),
355 (p->fmt.pixelformat >> 8) & 0xff,
356 (p->fmt.pixelformat >> 16) & 0xff,
357 (p->fmt.pixelformat >> 24) & 0xff,
358 p->fmt.bytesperline, p->fmt.sizeimage,
362 static void v4l_print_buftype(const void *arg, bool write_only)
364 pr_cont("type=%s\n", prt_names(*(u32 *)arg, v4l2_type_names));
367 static void v4l_print_modulator(const void *arg, bool write_only)
369 const struct v4l2_modulator *p = arg;
372 pr_cont("index=%u, txsubchans=0x%x", p->index, p->txsubchans);
374 pr_cont("index=%u, name=%s, capability=0x%x, "
375 "rangelow=%u, rangehigh=%u, txsubchans=0x%x\n",
376 p->index, p->name, p->capability,
377 p->rangelow, p->rangehigh, p->txsubchans);
380 static void v4l_print_tuner(const void *arg, bool write_only)
382 const struct v4l2_tuner *p = arg;
385 pr_cont("index=%u, audmode=%u\n", p->index, p->audmode);
387 pr_cont("index=%u, name=%s, type=%u, capability=0x%x, "
388 "rangelow=%u, rangehigh=%u, signal=%u, afc=%d, "
389 "rxsubchans=0x%x, audmode=%u\n",
390 p->index, p->name, p->type,
391 p->capability, p->rangelow,
392 p->rangehigh, p->signal, p->afc,
393 p->rxsubchans, p->audmode);
396 static void v4l_print_frequency(const void *arg, bool write_only)
398 const struct v4l2_frequency *p = arg;
400 pr_cont("tuner=%u, type=%u, frequency=%u\n",
401 p->tuner, p->type, p->frequency);
404 static void v4l_print_standard(const void *arg, bool write_only)
406 const struct v4l2_standard *p = arg;
408 pr_cont("index=%u, id=0x%Lx, name=%s, fps=%u/%u, "
409 "framelines=%u\n", p->index,
410 (unsigned long long)p->id, p->name,
411 p->frameperiod.numerator,
412 p->frameperiod.denominator,
416 static void v4l_print_std(const void *arg, bool write_only)
418 pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg);
421 static void v4l_print_hw_freq_seek(const void *arg, bool write_only)
423 const struct v4l2_hw_freq_seek *p = arg;
425 pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
426 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
429 static void v4l_print_requestbuffers(const void *arg, bool write_only)
431 const struct v4l2_requestbuffers *p = arg;
433 pr_cont("count=%d, type=%s, memory=%s\n",
435 prt_names(p->type, v4l2_type_names),
436 prt_names(p->memory, v4l2_memory_names));
439 static void v4l_print_buffer(const void *arg, bool write_only)
441 const struct v4l2_buffer *p = arg;
442 const struct v4l2_timecode *tc = &p->timecode;
443 const struct v4l2_plane *plane;
446 pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, "
447 "flags=0x%08x, field=%s, sequence=%d, memory=%s",
448 p->timestamp.tv_sec / 3600,
449 (int)(p->timestamp.tv_sec / 60) % 60,
450 (int)(p->timestamp.tv_sec % 60),
451 (long)p->timestamp.tv_usec,
453 prt_names(p->type, v4l2_type_names),
454 p->flags, prt_names(p->field, v4l2_field_names),
455 p->sequence, prt_names(p->memory, v4l2_memory_names));
457 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
459 for (i = 0; i < p->length; ++i) {
460 plane = &p->m.planes[i];
462 "plane %d: bytesused=%d, data_offset=0x%08x "
463 "offset/userptr=0x%lx, length=%d\n",
464 i, plane->bytesused, plane->data_offset,
465 plane->m.userptr, plane->length);
468 pr_cont("bytesused=%d, offset/userptr=0x%lx, length=%d\n",
469 p->bytesused, p->m.userptr, p->length);
472 printk(KERN_DEBUG "timecode=%02d:%02d:%02d type=%d, "
473 "flags=0x%08x, frames=%d, userbits=0x%08x\n",
474 tc->hours, tc->minutes, tc->seconds,
475 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
478 static void v4l_print_create_buffers(const void *arg, bool write_only)
480 const struct v4l2_create_buffers *p = arg;
482 pr_cont("index=%d, count=%d, memory=%s, ",
484 prt_names(p->memory, v4l2_memory_names));
485 v4l_print_format(&p->format, write_only);
488 static void v4l_print_streamparm(const void *arg, bool write_only)
490 const struct v4l2_streamparm *p = arg;
492 pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
494 if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
495 p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
496 const struct v4l2_captureparm *c = &p->parm.capture;
498 pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, "
499 "extendedmode=%d, readbuffers=%d\n",
500 c->capability, c->capturemode,
501 c->timeperframe.numerator, c->timeperframe.denominator,
502 c->extendedmode, c->readbuffers);
503 } else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT ||
504 p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
505 const struct v4l2_outputparm *c = &p->parm.output;
507 pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, "
508 "extendedmode=%d, writebuffers=%d\n",
509 c->capability, c->outputmode,
510 c->timeperframe.numerator, c->timeperframe.denominator,
511 c->extendedmode, c->writebuffers);
515 static void v4l_print_queryctrl(const void *arg, bool write_only)
517 const struct v4l2_queryctrl *p = arg;
519 pr_cont("id=0x%x, type=%d, name=%s, min/max=%d/%d, "
520 "step=%d, default=%d, flags=0x%08x\n",
521 p->id, p->type, p->name,
522 p->minimum, p->maximum,
523 p->step, p->default_value, p->flags);
526 static void v4l_print_querymenu(const void *arg, bool write_only)
528 const struct v4l2_querymenu *p = arg;
530 pr_cont("id=0x%x, index=%d\n", p->id, p->index);
533 static void v4l_print_control(const void *arg, bool write_only)
535 const struct v4l2_control *p = arg;
537 pr_cont("id=0x%x, value=%d\n", p->id, p->value);
540 static void v4l_print_ext_controls(const void *arg, bool write_only)
542 const struct v4l2_ext_controls *p = arg;
545 pr_cont("class=0x%x, count=%d, error_idx=%d",
546 p->ctrl_class, p->count, p->error_idx);
547 for (i = 0; i < p->count; i++) {
548 if (p->controls[i].size)
549 pr_cont(", id/val=0x%x/0x%x",
550 p->controls[i].id, p->controls[i].value);
552 pr_cont(", id/size=0x%x/%u",
553 p->controls[i].id, p->controls[i].size);
558 static void v4l_print_cropcap(const void *arg, bool write_only)
560 const struct v4l2_cropcap *p = arg;
562 pr_cont("type=%s, bounds wxh=%dx%d, x,y=%d,%d, "
563 "defrect wxh=%dx%d, x,y=%d,%d\n, "
564 "pixelaspect %d/%d\n",
565 prt_names(p->type, v4l2_type_names),
566 p->bounds.width, p->bounds.height,
567 p->bounds.left, p->bounds.top,
568 p->defrect.width, p->defrect.height,
569 p->defrect.left, p->defrect.top,
570 p->pixelaspect.numerator, p->pixelaspect.denominator);
573 static void v4l_print_crop(const void *arg, bool write_only)
575 const struct v4l2_crop *p = arg;
577 pr_cont("type=%s, wxh=%dx%d, x,y=%d,%d\n",
578 prt_names(p->type, v4l2_type_names),
579 p->c.width, p->c.height,
580 p->c.left, p->c.top);
583 static void v4l_print_selection(const void *arg, bool write_only)
585 const struct v4l2_selection *p = arg;
587 pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
588 prt_names(p->type, v4l2_type_names),
590 p->r.width, p->r.height, p->r.left, p->r.top);
593 static void v4l_print_jpegcompression(const void *arg, bool write_only)
595 const struct v4l2_jpegcompression *p = arg;
597 pr_cont("quality=%d, APPn=%d, APP_len=%d, "
598 "COM_len=%d, jpeg_markers=0x%x\n",
599 p->quality, p->APPn, p->APP_len,
600 p->COM_len, p->jpeg_markers);
603 static void v4l_print_enc_idx(const void *arg, bool write_only)
605 const struct v4l2_enc_idx *p = arg;
607 pr_cont("entries=%d, entries_cap=%d\n",
608 p->entries, p->entries_cap);
611 static void v4l_print_encoder_cmd(const void *arg, bool write_only)
613 const struct v4l2_encoder_cmd *p = arg;
615 pr_cont("cmd=%d, flags=0x%x\n",
619 static void v4l_print_decoder_cmd(const void *arg, bool write_only)
621 const struct v4l2_decoder_cmd *p = arg;
623 pr_cont("cmd=%d, flags=0x%x\n", p->cmd, p->flags);
625 if (p->cmd == V4L2_DEC_CMD_START)
626 pr_info("speed=%d, format=%u\n",
627 p->start.speed, p->start.format);
628 else if (p->cmd == V4L2_DEC_CMD_STOP)
629 pr_info("pts=%llu\n", p->stop.pts);
632 static void v4l_print_dbg_chip_ident(const void *arg, bool write_only)
634 const struct v4l2_dbg_chip_ident *p = arg;
636 pr_cont("type=%u, ", p->match.type);
637 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
638 pr_cont("name=%s, ", p->match.name);
640 pr_cont("addr=%u, ", p->match.addr);
641 pr_cont("chip_ident=%u, revision=0x%x\n",
642 p->ident, p->revision);
645 static void v4l_print_dbg_register(const void *arg, bool write_only)
647 const struct v4l2_dbg_register *p = arg;
649 pr_cont("type=%u, ", p->match.type);
650 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
651 pr_cont("name=%s, ", p->match.name);
653 pr_cont("addr=%u, ", p->match.addr);
654 pr_cont("reg=0x%llx, val=0x%llx\n",
658 static void v4l_print_dv_enum_presets(const void *arg, bool write_only)
660 const struct v4l2_dv_enum_preset *p = arg;
662 pr_cont("index=%u, preset=%u, name=%s, width=%u, height=%u\n",
663 p->index, p->preset, p->name, p->width, p->height);
666 static void v4l_print_dv_preset(const void *arg, bool write_only)
668 const struct v4l2_dv_preset *p = arg;
670 pr_cont("preset=%u\n", p->preset);
673 static void v4l_print_dv_timings(const void *arg, bool write_only)
675 const struct v4l2_dv_timings *p = arg;
678 case V4L2_DV_BT_656_1120:
679 pr_cont("type=bt-656/1120, interlaced=%u, "
681 "width=%u, height=%u, polarities=0x%x, "
682 "hfrontporch=%u, hsync=%u, "
683 "hbackporch=%u, vfrontporch=%u, "
684 "vsync=%u, vbackporch=%u, "
685 "il_vfrontporch=%u, il_vsync=%u, "
686 "il_vbackporch=%u, standards=0x%x, flags=0x%x\n",
687 p->bt.interlaced, p->bt.pixelclock,
688 p->bt.width, p->bt.height,
689 p->bt.polarities, p->bt.hfrontporch,
690 p->bt.hsync, p->bt.hbackporch,
691 p->bt.vfrontporch, p->bt.vsync,
692 p->bt.vbackporch, p->bt.il_vfrontporch,
693 p->bt.il_vsync, p->bt.il_vbackporch,
694 p->bt.standards, p->bt.flags);
697 pr_cont("type=%d\n", p->type);
702 static void v4l_print_enum_dv_timings(const void *arg, bool write_only)
704 const struct v4l2_enum_dv_timings *p = arg;
706 pr_cont("index=%u, ", p->index);
707 v4l_print_dv_timings(&p->timings, write_only);
710 static void v4l_print_dv_timings_cap(const void *arg, bool write_only)
712 const struct v4l2_dv_timings_cap *p = arg;
715 case V4L2_DV_BT_656_1120:
716 pr_cont("type=bt-656/1120, width=%u-%u, height=%u-%u, "
717 "pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n",
718 p->bt.min_width, p->bt.max_width,
719 p->bt.min_height, p->bt.max_height,
720 p->bt.min_pixelclock, p->bt.max_pixelclock,
721 p->bt.standards, p->bt.capabilities);
724 pr_cont("type=%u\n", p->type);
729 static void v4l_print_frmsizeenum(const void *arg, bool write_only)
731 const struct v4l2_frmsizeenum *p = arg;
733 pr_cont("index=%u, pixelformat=%c%c%c%c, type=%u",
735 (p->pixel_format & 0xff),
736 (p->pixel_format >> 8) & 0xff,
737 (p->pixel_format >> 16) & 0xff,
738 (p->pixel_format >> 24) & 0xff,
741 case V4L2_FRMSIZE_TYPE_DISCRETE:
742 pr_cont(" wxh=%ux%u\n",
743 p->discrete.width, p->discrete.height);
745 case V4L2_FRMSIZE_TYPE_STEPWISE:
746 pr_cont(" min=%ux%u, max=%ux%u, step=%ux%u\n",
747 p->stepwise.min_width, p->stepwise.min_height,
748 p->stepwise.step_width, p->stepwise.step_height,
749 p->stepwise.max_width, p->stepwise.max_height);
751 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
759 static void v4l_print_frmivalenum(const void *arg, bool write_only)
761 const struct v4l2_frmivalenum *p = arg;
763 pr_cont("index=%u, pixelformat=%c%c%c%c, wxh=%ux%u, type=%u",
765 (p->pixel_format & 0xff),
766 (p->pixel_format >> 8) & 0xff,
767 (p->pixel_format >> 16) & 0xff,
768 (p->pixel_format >> 24) & 0xff,
769 p->width, p->height, p->type);
771 case V4L2_FRMIVAL_TYPE_DISCRETE:
772 pr_cont(" fps=%d/%d\n",
773 p->discrete.numerator,
774 p->discrete.denominator);
776 case V4L2_FRMIVAL_TYPE_STEPWISE:
777 pr_cont(" min=%d/%d, max=%d/%d, step=%d/%d\n",
778 p->stepwise.min.numerator,
779 p->stepwise.min.denominator,
780 p->stepwise.max.numerator,
781 p->stepwise.max.denominator,
782 p->stepwise.step.numerator,
783 p->stepwise.step.denominator);
785 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
793 static void v4l_print_event(const void *arg, bool write_only)
795 const struct v4l2_event *p = arg;
796 const struct v4l2_event_ctrl *c;
798 pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, "
799 "timestamp=%lu.%9.9lu\n",
800 p->type, p->pending, p->sequence, p->id,
801 p->timestamp.tv_sec, p->timestamp.tv_nsec);
803 case V4L2_EVENT_VSYNC:
804 printk(KERN_DEBUG "field=%s\n",
805 prt_names(p->u.vsync.field, v4l2_field_names));
807 case V4L2_EVENT_CTRL:
809 printk(KERN_DEBUG "changes=0x%x, type=%u, ",
810 c->changes, c->type);
811 if (c->type == V4L2_CTRL_TYPE_INTEGER64)
812 pr_cont("value64=%lld, ", c->value64);
814 pr_cont("value=%d, ", c->value);
815 pr_cont("flags=0x%x, minimum=%d, maximum=%d, step=%d,"
816 " default_value=%d\n",
817 c->flags, c->minimum, c->maximum,
818 c->step, c->default_value);
820 case V4L2_EVENT_FRAME_SYNC:
821 pr_cont("frame_sequence=%u\n",
822 p->u.frame_sync.frame_sequence);
827 static void v4l_print_event_subscription(const void *arg, bool write_only)
829 const struct v4l2_event_subscription *p = arg;
831 pr_cont("type=0x%x, id=0x%x, flags=0x%x\n",
832 p->type, p->id, p->flags);
835 static void v4l_print_sliced_vbi_cap(const void *arg, bool write_only)
837 const struct v4l2_sliced_vbi_cap *p = arg;
840 pr_cont("type=%s, service_set=0x%08x\n",
841 prt_names(p->type, v4l2_type_names), p->service_set);
842 for (i = 0; i < 24; i++)
843 printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i,
844 p->service_lines[0][i],
845 p->service_lines[1][i]);
848 static void v4l_print_u32(const void *arg, bool write_only)
850 pr_cont("value=%u\n", *(const u32 *)arg);
853 static void v4l_print_newline(const void *arg, bool write_only)
858 static void v4l_print_default(const void *arg, bool write_only)
860 pr_cont("driver-specific ioctl\n");
863 static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
867 /* zero the reserved fields */
868 c->reserved[0] = c->reserved[1] = 0;
869 for (i = 0; i < c->count; i++)
870 c->controls[i].reserved2[0] = 0;
872 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
873 when using extended controls.
874 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
875 is it allowed for backwards compatibility.
877 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
879 /* Check that all controls are from the same control class. */
880 for (i = 0; i < c->count; i++) {
881 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
889 static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
895 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
896 if (ops->vidioc_g_fmt_vid_cap ||
897 ops->vidioc_g_fmt_vid_cap_mplane)
900 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
901 if (ops->vidioc_g_fmt_vid_cap_mplane)
904 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
905 if (ops->vidioc_g_fmt_vid_overlay)
908 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
909 if (ops->vidioc_g_fmt_vid_out ||
910 ops->vidioc_g_fmt_vid_out_mplane)
913 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
914 if (ops->vidioc_g_fmt_vid_out_mplane)
917 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
918 if (ops->vidioc_g_fmt_vid_out_overlay)
921 case V4L2_BUF_TYPE_VBI_CAPTURE:
922 if (ops->vidioc_g_fmt_vbi_cap)
925 case V4L2_BUF_TYPE_VBI_OUTPUT:
926 if (ops->vidioc_g_fmt_vbi_out)
929 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
930 if (ops->vidioc_g_fmt_sliced_vbi_cap)
933 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
934 if (ops->vidioc_g_fmt_sliced_vbi_out)
937 case V4L2_BUF_TYPE_PRIVATE:
938 if (ops->vidioc_g_fmt_type_private)
945 static int v4l_querycap(const struct v4l2_ioctl_ops *ops,
946 struct file *file, void *fh, void *arg)
948 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
950 cap->version = LINUX_VERSION_CODE;
951 return ops->vidioc_querycap(file, fh, cap);
954 static int v4l_s_input(const struct v4l2_ioctl_ops *ops,
955 struct file *file, void *fh, void *arg)
957 return ops->vidioc_s_input(file, fh, *(unsigned int *)arg);
960 static int v4l_s_output(const struct v4l2_ioctl_ops *ops,
961 struct file *file, void *fh, void *arg)
963 return ops->vidioc_s_output(file, fh, *(unsigned int *)arg);
966 static int v4l_g_priority(const struct v4l2_ioctl_ops *ops,
967 struct file *file, void *fh, void *arg)
969 struct video_device *vfd;
972 if (ops->vidioc_g_priority)
973 return ops->vidioc_g_priority(file, fh, arg);
974 vfd = video_devdata(file);
975 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
979 static int v4l_s_priority(const struct v4l2_ioctl_ops *ops,
980 struct file *file, void *fh, void *arg)
982 struct video_device *vfd;
986 if (ops->vidioc_s_priority)
987 return ops->vidioc_s_priority(file, fh, *p);
988 vfd = video_devdata(file);
989 vfh = file->private_data;
990 return v4l2_prio_change(&vfd->v4l2_dev->prio, &vfh->prio, *p);
993 static int v4l_enuminput(const struct v4l2_ioctl_ops *ops,
994 struct file *file, void *fh, void *arg)
996 struct v4l2_input *p = arg;
999 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1000 * CAP_STD here based on ioctl handler provided by the
1001 * driver. If the driver doesn't support these
1002 * for a specific input, it must override these flags.
1004 if (ops->vidioc_s_std)
1005 p->capabilities |= V4L2_IN_CAP_STD;
1006 if (ops->vidioc_s_dv_preset)
1007 p->capabilities |= V4L2_IN_CAP_PRESETS;
1008 if (ops->vidioc_s_dv_timings)
1009 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1011 return ops->vidioc_enum_input(file, fh, p);
1014 static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops,
1015 struct file *file, void *fh, void *arg)
1017 struct v4l2_output *p = arg;
1020 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1021 * CAP_STD here based on ioctl handler provided by the
1022 * driver. If the driver doesn't support these
1023 * for a specific output, it must override these flags.
1025 if (ops->vidioc_s_std)
1026 p->capabilities |= V4L2_OUT_CAP_STD;
1027 if (ops->vidioc_s_dv_preset)
1028 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1029 if (ops->vidioc_s_dv_timings)
1030 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1032 return ops->vidioc_enum_output(file, fh, p);
1035 static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
1036 struct file *file, void *fh, void *arg)
1038 struct v4l2_fmtdesc *p = arg;
1041 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1042 if (unlikely(!ops->vidioc_enum_fmt_vid_cap))
1044 return ops->vidioc_enum_fmt_vid_cap(file, fh, arg);
1045 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1046 if (unlikely(!ops->vidioc_enum_fmt_vid_cap_mplane))
1048 return ops->vidioc_enum_fmt_vid_cap_mplane(file, fh, arg);
1049 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1050 if (unlikely(!ops->vidioc_enum_fmt_vid_overlay))
1052 return ops->vidioc_enum_fmt_vid_overlay(file, fh, arg);
1053 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1054 if (unlikely(!ops->vidioc_enum_fmt_vid_out))
1056 return ops->vidioc_enum_fmt_vid_out(file, fh, arg);
1057 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1058 if (unlikely(!ops->vidioc_enum_fmt_vid_out_mplane))
1060 return ops->vidioc_enum_fmt_vid_out_mplane(file, fh, arg);
1061 case V4L2_BUF_TYPE_PRIVATE:
1062 if (unlikely(!ops->vidioc_enum_fmt_type_private))
1064 return ops->vidioc_enum_fmt_type_private(file, fh, arg);
1069 static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
1070 struct file *file, void *fh, void *arg)
1072 struct v4l2_format *p = arg;
1075 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1076 if (unlikely(!ops->vidioc_g_fmt_vid_cap))
1078 return ops->vidioc_g_fmt_vid_cap(file, fh, arg);
1079 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1080 if (unlikely(!ops->vidioc_g_fmt_vid_cap_mplane))
1082 return ops->vidioc_g_fmt_vid_cap_mplane(file, fh, arg);
1083 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1084 if (unlikely(!ops->vidioc_g_fmt_vid_overlay))
1086 return ops->vidioc_g_fmt_vid_overlay(file, fh, arg);
1087 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1088 if (unlikely(!ops->vidioc_g_fmt_vid_out))
1090 return ops->vidioc_g_fmt_vid_out(file, fh, arg);
1091 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1092 if (unlikely(!ops->vidioc_g_fmt_vid_out_mplane))
1094 return ops->vidioc_g_fmt_vid_out_mplane(file, fh, arg);
1095 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1096 if (unlikely(!ops->vidioc_g_fmt_vid_out_overlay))
1098 return ops->vidioc_g_fmt_vid_out_overlay(file, fh, arg);
1099 case V4L2_BUF_TYPE_VBI_CAPTURE:
1100 if (unlikely(!ops->vidioc_g_fmt_vbi_cap))
1102 return ops->vidioc_g_fmt_vbi_cap(file, fh, arg);
1103 case V4L2_BUF_TYPE_VBI_OUTPUT:
1104 if (unlikely(!ops->vidioc_g_fmt_vbi_out))
1106 return ops->vidioc_g_fmt_vbi_out(file, fh, arg);
1107 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1108 if (unlikely(!ops->vidioc_g_fmt_sliced_vbi_cap))
1110 return ops->vidioc_g_fmt_sliced_vbi_cap(file, fh, arg);
1111 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1112 if (unlikely(!ops->vidioc_g_fmt_sliced_vbi_out))
1114 return ops->vidioc_g_fmt_sliced_vbi_out(file, fh, arg);
1115 case V4L2_BUF_TYPE_PRIVATE:
1116 if (unlikely(!ops->vidioc_g_fmt_type_private))
1118 return ops->vidioc_g_fmt_type_private(file, fh, arg);
1123 static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
1124 struct file *file, void *fh, void *arg)
1126 struct v4l2_format *p = arg;
1129 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1130 if (unlikely(!ops->vidioc_s_fmt_vid_cap))
1132 CLEAR_AFTER_FIELD(p, fmt.pix);
1133 return ops->vidioc_s_fmt_vid_cap(file, fh, arg);
1134 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1135 if (unlikely(!ops->vidioc_s_fmt_vid_cap_mplane))
1137 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
1138 return ops->vidioc_s_fmt_vid_cap_mplane(file, fh, arg);
1139 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1140 if (unlikely(!ops->vidioc_s_fmt_vid_overlay))
1142 CLEAR_AFTER_FIELD(p, fmt.win);
1143 return ops->vidioc_s_fmt_vid_overlay(file, fh, arg);
1144 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1145 if (unlikely(!ops->vidioc_s_fmt_vid_out))
1147 CLEAR_AFTER_FIELD(p, fmt.pix);
1148 return ops->vidioc_s_fmt_vid_out(file, fh, arg);
1149 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1150 if (unlikely(!ops->vidioc_s_fmt_vid_out_mplane))
1152 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
1153 return ops->vidioc_s_fmt_vid_out_mplane(file, fh, arg);
1154 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1155 if (unlikely(!ops->vidioc_s_fmt_vid_out_overlay))
1157 CLEAR_AFTER_FIELD(p, fmt.win);
1158 return ops->vidioc_s_fmt_vid_out_overlay(file, fh, arg);
1159 case V4L2_BUF_TYPE_VBI_CAPTURE:
1160 if (unlikely(!ops->vidioc_s_fmt_vbi_cap))
1162 CLEAR_AFTER_FIELD(p, fmt.vbi);
1163 return ops->vidioc_s_fmt_vbi_cap(file, fh, arg);
1164 case V4L2_BUF_TYPE_VBI_OUTPUT:
1165 if (unlikely(!ops->vidioc_s_fmt_vbi_out))
1167 CLEAR_AFTER_FIELD(p, fmt.vbi);
1168 return ops->vidioc_s_fmt_vbi_out(file, fh, arg);
1169 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1170 if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_cap))
1172 CLEAR_AFTER_FIELD(p, fmt.sliced);
1173 return ops->vidioc_s_fmt_sliced_vbi_cap(file, fh, arg);
1174 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1175 if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_out))
1177 CLEAR_AFTER_FIELD(p, fmt.sliced);
1178 return ops->vidioc_s_fmt_sliced_vbi_out(file, fh, arg);
1179 case V4L2_BUF_TYPE_PRIVATE:
1180 if (unlikely(!ops->vidioc_s_fmt_type_private))
1182 return ops->vidioc_s_fmt_type_private(file, fh, arg);
1187 static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops,
1188 struct file *file, void *fh, void *arg)
1190 struct v4l2_format *p = arg;
1193 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1194 if (unlikely(!ops->vidioc_try_fmt_vid_cap))
1196 CLEAR_AFTER_FIELD(p, fmt.pix);
1197 return ops->vidioc_try_fmt_vid_cap(file, fh, arg);
1198 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1199 if (unlikely(!ops->vidioc_try_fmt_vid_cap_mplane))
1201 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
1202 return ops->vidioc_try_fmt_vid_cap_mplane(file, fh, arg);
1203 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1204 if (unlikely(!ops->vidioc_try_fmt_vid_overlay))
1206 CLEAR_AFTER_FIELD(p, fmt.win);
1207 return ops->vidioc_try_fmt_vid_overlay(file, fh, arg);
1208 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1209 if (unlikely(!ops->vidioc_try_fmt_vid_out))
1211 CLEAR_AFTER_FIELD(p, fmt.pix);
1212 return ops->vidioc_try_fmt_vid_out(file, fh, arg);
1213 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1214 if (unlikely(!ops->vidioc_try_fmt_vid_out_mplane))
1216 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
1217 return ops->vidioc_try_fmt_vid_out_mplane(file, fh, arg);
1218 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1219 if (unlikely(!ops->vidioc_try_fmt_vid_out_overlay))
1221 CLEAR_AFTER_FIELD(p, fmt.win);
1222 return ops->vidioc_try_fmt_vid_out_overlay(file, fh, arg);
1223 case V4L2_BUF_TYPE_VBI_CAPTURE:
1224 if (unlikely(!ops->vidioc_try_fmt_vbi_cap))
1226 CLEAR_AFTER_FIELD(p, fmt.vbi);
1227 return ops->vidioc_try_fmt_vbi_cap(file, fh, arg);
1228 case V4L2_BUF_TYPE_VBI_OUTPUT:
1229 if (unlikely(!ops->vidioc_try_fmt_vbi_out))
1231 CLEAR_AFTER_FIELD(p, fmt.vbi);
1232 return ops->vidioc_try_fmt_vbi_out(file, fh, arg);
1233 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1234 if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_cap))
1236 CLEAR_AFTER_FIELD(p, fmt.sliced);
1237 return ops->vidioc_try_fmt_sliced_vbi_cap(file, fh, arg);
1238 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1239 if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_out))
1241 CLEAR_AFTER_FIELD(p, fmt.sliced);
1242 return ops->vidioc_try_fmt_sliced_vbi_out(file, fh, arg);
1243 case V4L2_BUF_TYPE_PRIVATE:
1244 if (unlikely(!ops->vidioc_try_fmt_type_private))
1246 return ops->vidioc_try_fmt_type_private(file, fh, arg);
1251 static int v4l_streamon(const struct v4l2_ioctl_ops *ops,
1252 struct file *file, void *fh, void *arg)
1254 return ops->vidioc_streamon(file, fh, *(unsigned int *)arg);
1257 static int v4l_streamoff(const struct v4l2_ioctl_ops *ops,
1258 struct file *file, void *fh, void *arg)
1260 return ops->vidioc_streamoff(file, fh, *(unsigned int *)arg);
1263 static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops,
1264 struct file *file, void *fh, void *arg)
1266 struct video_device *vfd = video_devdata(file);
1267 struct v4l2_tuner *p = arg;
1269 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1270 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1271 return ops->vidioc_g_tuner(file, fh, p);
1274 static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops,
1275 struct file *file, void *fh, void *arg)
1277 struct video_device *vfd = video_devdata(file);
1278 struct v4l2_tuner *p = arg;
1280 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1281 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1282 return ops->vidioc_s_tuner(file, fh, p);
1285 static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
1286 struct file *file, void *fh, void *arg)
1288 struct video_device *vfd = video_devdata(file);
1289 struct v4l2_frequency *p = arg;
1291 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1292 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1293 return ops->vidioc_g_frequency(file, fh, p);
1296 static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
1297 struct file *file, void *fh, void *arg)
1299 struct video_device *vfd = video_devdata(file);
1300 struct v4l2_frequency *p = arg;
1301 enum v4l2_tuner_type type;
1303 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1304 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1305 if (p->type != type)
1307 return ops->vidioc_s_frequency(file, fh, p);
1310 static int v4l_enumstd(const struct v4l2_ioctl_ops *ops,
1311 struct file *file, void *fh, void *arg)
1313 struct video_device *vfd = video_devdata(file);
1314 struct v4l2_standard *p = arg;
1315 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1316 unsigned int index = p->index, i, j = 0;
1317 const char *descr = "";
1319 /* Return norm array in a canonical way */
1320 for (i = 0; i <= index && id; i++) {
1321 /* last std value in the standards array is 0, so this
1322 while always ends there since (id & 0) == 0. */
1323 while ((id & standards[j].std) != standards[j].std)
1325 curr_id = standards[j].std;
1326 descr = standards[j].descr;
1330 if (curr_id != V4L2_STD_PAL &&
1331 curr_id != V4L2_STD_SECAM &&
1332 curr_id != V4L2_STD_NTSC)
1338 v4l2_video_std_construct(p, curr_id, descr);
1342 static int v4l_g_std(const struct v4l2_ioctl_ops *ops,
1343 struct file *file, void *fh, void *arg)
1345 struct video_device *vfd = video_devdata(file);
1346 v4l2_std_id *id = arg;
1348 /* Calls the specific handler */
1349 if (ops->vidioc_g_std)
1350 return ops->vidioc_g_std(file, fh, arg);
1351 if (vfd->current_norm) {
1352 *id = vfd->current_norm;
1358 static int v4l_s_std(const struct v4l2_ioctl_ops *ops,
1359 struct file *file, void *fh, void *arg)
1361 struct video_device *vfd = video_devdata(file);
1362 v4l2_std_id *id = arg, norm;
1365 norm = (*id) & vfd->tvnorms;
1366 if (vfd->tvnorms && !norm) /* Check if std is supported */
1369 /* Calls the specific handler */
1370 ret = ops->vidioc_s_std(file, fh, &norm);
1372 /* Updates standard information */
1374 vfd->current_norm = norm;
1378 static int v4l_querystd(const struct v4l2_ioctl_ops *ops,
1379 struct file *file, void *fh, void *arg)
1381 struct video_device *vfd = video_devdata(file);
1382 v4l2_std_id *p = arg;
1385 * If nothing detected, it should return all supported
1387 * Drivers just need to mask the std argument, in order
1388 * to remove the standards that don't apply from the mask.
1389 * This means that tuners, audio and video decoders can join
1390 * their efforts to improve the standards detection.
1393 return ops->vidioc_querystd(file, fh, arg);
1396 static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
1397 struct file *file, void *fh, void *arg)
1399 struct video_device *vfd = video_devdata(file);
1400 struct v4l2_hw_freq_seek *p = arg;
1401 enum v4l2_tuner_type type;
1403 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1404 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1405 if (p->type != type)
1407 return ops->vidioc_s_hw_freq_seek(file, fh, p);
1410 static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops,
1411 struct file *file, void *fh, void *arg)
1413 struct v4l2_requestbuffers *p = arg;
1414 int ret = check_fmt(ops, p->type);
1419 if (p->type < V4L2_BUF_TYPE_PRIVATE)
1420 CLEAR_AFTER_FIELD(p, memory);
1422 return ops->vidioc_reqbufs(file, fh, p);
1425 static int v4l_querybuf(const struct v4l2_ioctl_ops *ops,
1426 struct file *file, void *fh, void *arg)
1428 struct v4l2_buffer *p = arg;
1429 int ret = check_fmt(ops, p->type);
1431 return ret ? ret : ops->vidioc_querybuf(file, fh, p);
1434 static int v4l_qbuf(const struct v4l2_ioctl_ops *ops,
1435 struct file *file, void *fh, void *arg)
1437 struct v4l2_buffer *p = arg;
1438 int ret = check_fmt(ops, p->type);
1440 return ret ? ret : ops->vidioc_qbuf(file, fh, p);
1443 static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops,
1444 struct file *file, void *fh, void *arg)
1446 struct v4l2_buffer *p = arg;
1447 int ret = check_fmt(ops, p->type);
1449 return ret ? ret : ops->vidioc_dqbuf(file, fh, p);
1452 static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
1453 struct file *file, void *fh, void *arg)
1455 struct v4l2_create_buffers *create = arg;
1456 int ret = check_fmt(ops, create->format.type);
1458 return ret ? ret : ops->vidioc_create_bufs(file, fh, create);
1461 static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,
1462 struct file *file, void *fh, void *arg)
1464 struct v4l2_buffer *b = arg;
1465 int ret = check_fmt(ops, b->type);
1467 return ret ? ret : ops->vidioc_prepare_buf(file, fh, b);
1470 static int v4l_g_parm(const struct v4l2_ioctl_ops *ops,
1471 struct file *file, void *fh, void *arg)
1473 struct video_device *vfd = video_devdata(file);
1474 struct v4l2_streamparm *p = arg;
1476 int ret = check_fmt(ops, p->type);
1480 if (ops->vidioc_g_parm)
1481 return ops->vidioc_g_parm(file, fh, p);
1482 std = vfd->current_norm;
1483 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1484 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1486 p->parm.capture.readbuffers = 2;
1487 if (ops->vidioc_g_std)
1488 ret = ops->vidioc_g_std(file, fh, &std);
1490 v4l2_video_std_frame_period(std,
1491 &p->parm.capture.timeperframe);
1495 static int v4l_s_parm(const struct v4l2_ioctl_ops *ops,
1496 struct file *file, void *fh, void *arg)
1498 struct v4l2_streamparm *p = arg;
1499 int ret = check_fmt(ops, p->type);
1501 return ret ? ret : ops->vidioc_s_parm(file, fh, p);
1504 static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
1505 struct file *file, void *fh, void *arg)
1507 struct video_device *vfd = video_devdata(file);
1508 struct v4l2_queryctrl *p = arg;
1509 struct v4l2_fh *vfh = fh;
1511 if (vfh && vfh->ctrl_handler)
1512 return v4l2_queryctrl(vfh->ctrl_handler, p);
1513 if (vfd->ctrl_handler)
1514 return v4l2_queryctrl(vfd->ctrl_handler, p);
1515 if (ops->vidioc_queryctrl)
1516 return ops->vidioc_queryctrl(file, fh, p);
1520 static int v4l_querymenu(const struct v4l2_ioctl_ops *ops,
1521 struct file *file, void *fh, void *arg)
1523 struct video_device *vfd = video_devdata(file);
1524 struct v4l2_querymenu *p = arg;
1525 struct v4l2_fh *vfh = fh;
1527 if (vfh && vfh->ctrl_handler)
1528 return v4l2_querymenu(vfh->ctrl_handler, p);
1529 if (vfd->ctrl_handler)
1530 return v4l2_querymenu(vfd->ctrl_handler, p);
1531 if (ops->vidioc_querymenu)
1532 return ops->vidioc_querymenu(file, fh, p);
1536 static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops,
1537 struct file *file, void *fh, void *arg)
1539 struct video_device *vfd = video_devdata(file);
1540 struct v4l2_control *p = arg;
1541 struct v4l2_fh *vfh = fh;
1542 struct v4l2_ext_controls ctrls;
1543 struct v4l2_ext_control ctrl;
1545 if (vfh && vfh->ctrl_handler)
1546 return v4l2_g_ctrl(vfh->ctrl_handler, p);
1547 if (vfd->ctrl_handler)
1548 return v4l2_g_ctrl(vfd->ctrl_handler, p);
1549 if (ops->vidioc_g_ctrl)
1550 return ops->vidioc_g_ctrl(file, fh, p);
1551 if (ops->vidioc_g_ext_ctrls == NULL)
1554 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1556 ctrls.controls = &ctrl;
1558 ctrl.value = p->value;
1559 if (check_ext_ctrls(&ctrls, 1)) {
1560 int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1563 p->value = ctrl.value;
1569 static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops,
1570 struct file *file, void *fh, void *arg)
1572 struct video_device *vfd = video_devdata(file);
1573 struct v4l2_control *p = arg;
1574 struct v4l2_fh *vfh = fh;
1575 struct v4l2_ext_controls ctrls;
1576 struct v4l2_ext_control ctrl;
1578 if (vfh && vfh->ctrl_handler)
1579 return v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
1580 if (vfd->ctrl_handler)
1581 return v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
1582 if (ops->vidioc_s_ctrl)
1583 return ops->vidioc_s_ctrl(file, fh, p);
1584 if (ops->vidioc_s_ext_ctrls == NULL)
1587 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1589 ctrls.controls = &ctrl;
1591 ctrl.value = p->value;
1592 if (check_ext_ctrls(&ctrls, 1))
1593 return ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1597 static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
1598 struct file *file, void *fh, void *arg)
1600 struct video_device *vfd = video_devdata(file);
1601 struct v4l2_ext_controls *p = arg;
1602 struct v4l2_fh *vfh = fh;
1604 p->error_idx = p->count;
1605 if (vfh && vfh->ctrl_handler)
1606 return v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1607 if (vfd->ctrl_handler)
1608 return v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1609 if (ops->vidioc_g_ext_ctrls == NULL)
1611 return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) :
1615 static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
1616 struct file *file, void *fh, void *arg)
1618 struct video_device *vfd = video_devdata(file);
1619 struct v4l2_ext_controls *p = arg;
1620 struct v4l2_fh *vfh = fh;
1622 p->error_idx = p->count;
1623 if (vfh && vfh->ctrl_handler)
1624 return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
1625 if (vfd->ctrl_handler)
1626 return v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
1627 if (ops->vidioc_s_ext_ctrls == NULL)
1629 return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) :
1633 static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
1634 struct file *file, void *fh, void *arg)
1636 struct video_device *vfd = video_devdata(file);
1637 struct v4l2_ext_controls *p = arg;
1638 struct v4l2_fh *vfh = fh;
1640 p->error_idx = p->count;
1641 if (vfh && vfh->ctrl_handler)
1642 return v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1643 if (vfd->ctrl_handler)
1644 return v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1645 if (ops->vidioc_try_ext_ctrls == NULL)
1647 return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) :
1651 static int v4l_g_crop(const struct v4l2_ioctl_ops *ops,
1652 struct file *file, void *fh, void *arg)
1654 struct v4l2_crop *p = arg;
1655 struct v4l2_selection s = {
1660 if (ops->vidioc_g_crop)
1661 return ops->vidioc_g_crop(file, fh, p);
1662 /* simulate capture crop using selection api */
1664 /* crop means compose for output devices */
1665 if (V4L2_TYPE_IS_OUTPUT(p->type))
1666 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1668 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1670 ret = ops->vidioc_g_selection(file, fh, &s);
1672 /* copying results to old structure on success */
1678 static int v4l_s_crop(const struct v4l2_ioctl_ops *ops,
1679 struct file *file, void *fh, void *arg)
1681 struct v4l2_crop *p = arg;
1682 struct v4l2_selection s = {
1687 if (ops->vidioc_s_crop)
1688 return ops->vidioc_s_crop(file, fh, p);
1689 /* simulate capture crop using selection api */
1691 /* crop means compose for output devices */
1692 if (V4L2_TYPE_IS_OUTPUT(p->type))
1693 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1695 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1697 return ops->vidioc_s_selection(file, fh, &s);
1700 static int v4l_cropcap(const struct v4l2_ioctl_ops *ops,
1701 struct file *file, void *fh, void *arg)
1703 struct v4l2_cropcap *p = arg;
1704 struct v4l2_selection s = { .type = p->type };
1707 if (ops->vidioc_cropcap)
1708 return ops->vidioc_cropcap(file, fh, p);
1710 /* obtaining bounds */
1711 if (V4L2_TYPE_IS_OUTPUT(p->type))
1712 s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
1714 s.target = V4L2_SEL_TGT_CROP_BOUNDS;
1716 ret = ops->vidioc_g_selection(file, fh, &s);
1721 /* obtaining defrect */
1722 if (V4L2_TYPE_IS_OUTPUT(p->type))
1723 s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
1725 s.target = V4L2_SEL_TGT_CROP_DEFAULT;
1727 ret = ops->vidioc_g_selection(file, fh, &s);
1732 /* setting trivial pixelaspect */
1733 p->pixelaspect.numerator = 1;
1734 p->pixelaspect.denominator = 1;
1738 static int v4l_log_status(const struct v4l2_ioctl_ops *ops,
1739 struct file *file, void *fh, void *arg)
1741 struct video_device *vfd = video_devdata(file);
1745 pr_info("%s: ================= START STATUS =================\n",
1746 vfd->v4l2_dev->name);
1747 ret = ops->vidioc_log_status(file, fh);
1749 pr_info("%s: ================== END STATUS ==================\n",
1750 vfd->v4l2_dev->name);
1754 static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
1755 struct file *file, void *fh, void *arg)
1757 #ifdef CONFIG_VIDEO_ADV_DEBUG
1758 struct v4l2_dbg_register *p = arg;
1760 if (!capable(CAP_SYS_ADMIN))
1762 return ops->vidioc_g_register(file, fh, p);
1768 static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
1769 struct file *file, void *fh, void *arg)
1771 #ifdef CONFIG_VIDEO_ADV_DEBUG
1772 struct v4l2_dbg_register *p = arg;
1774 if (!capable(CAP_SYS_ADMIN))
1776 return ops->vidioc_s_register(file, fh, p);
1782 static int v4l_dbg_g_chip_ident(const struct v4l2_ioctl_ops *ops,
1783 struct file *file, void *fh, void *arg)
1785 struct v4l2_dbg_chip_ident *p = arg;
1787 p->ident = V4L2_IDENT_NONE;
1789 return ops->vidioc_g_chip_ident(file, fh, p);
1792 static int v4l_dqevent(const struct v4l2_ioctl_ops *ops,
1793 struct file *file, void *fh, void *arg)
1795 return v4l2_event_dequeue(fh, arg, file->f_flags & O_NONBLOCK);
1798 static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops,
1799 struct file *file, void *fh, void *arg)
1801 return ops->vidioc_subscribe_event(fh, arg);
1804 static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops,
1805 struct file *file, void *fh, void *arg)
1807 return ops->vidioc_unsubscribe_event(fh, arg);
1810 static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops,
1811 struct file *file, void *fh, void *arg)
1813 struct v4l2_sliced_vbi_cap *p = arg;
1815 /* Clear up to type, everything after type is zeroed already */
1816 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1818 return ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1821 struct v4l2_ioctl_info {
1824 const char * const name;
1827 int (*func)(const struct v4l2_ioctl_ops *ops,
1828 struct file *file, void *fh, void *p);
1830 void (*debug)(const void *arg, bool write_only);
1833 /* This control needs a priority check */
1834 #define INFO_FL_PRIO (1 << 0)
1835 /* This control can be valid if the filehandle passes a control handler. */
1836 #define INFO_FL_CTRL (1 << 1)
1837 /* This is a standard ioctl, no need for special code */
1838 #define INFO_FL_STD (1 << 2)
1839 /* This is ioctl has its own function */
1840 #define INFO_FL_FUNC (1 << 3)
1841 /* Zero struct from after the field to the end */
1842 #define INFO_FL_CLEAR(v4l2_struct, field) \
1843 ((offsetof(struct v4l2_struct, field) + \
1844 sizeof(((struct v4l2_struct *)0)->field)) << 16)
1845 #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
1847 #define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags) \
1848 [_IOC_NR(_ioctl)] = { \
1850 .flags = _flags | INFO_FL_STD, \
1852 .offset = offsetof(struct v4l2_ioctl_ops, _vidioc), \
1856 #define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags) \
1857 [_IOC_NR(_ioctl)] = { \
1859 .flags = _flags | INFO_FL_FUNC, \
1865 static struct v4l2_ioctl_info v4l2_ioctls[] = {
1866 IOCTL_INFO_FNC(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0),
1867 IOCTL_INFO_FNC(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
1868 IOCTL_INFO_FNC(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, INFO_FL_CLEAR(v4l2_format, type)),
1869 IOCTL_INFO_FNC(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
1870 IOCTL_INFO_FNC(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO),
1871 IOCTL_INFO_FNC(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_CLEAR(v4l2_buffer, length)),
1872 IOCTL_INFO_STD(VIDIOC_G_FBUF, vidioc_g_fbuf, v4l_print_framebuffer, 0),
1873 IOCTL_INFO_STD(VIDIOC_S_FBUF, vidioc_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO),
1874 IOCTL_INFO_STD(VIDIOC_OVERLAY, vidioc_overlay, v4l_print_u32, INFO_FL_PRIO),
1875 IOCTL_INFO_FNC(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, 0),
1876 IOCTL_INFO_FNC(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, 0),
1877 IOCTL_INFO_FNC(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO),
1878 IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO),
1879 IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)),
1880 IOCTL_INFO_FNC(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO),
1881 IOCTL_INFO_FNC(VIDIOC_G_STD, v4l_g_std, v4l_print_std, 0),
1882 IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO),
1883 IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)),
1884 IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)),
1885 IOCTL_INFO_FNC(VIDIOC_G_CTRL, v4l_g_ctrl, v4l_print_control, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_control, id)),
1886 IOCTL_INFO_FNC(VIDIOC_S_CTRL, v4l_s_ctrl, v4l_print_control, INFO_FL_PRIO | INFO_FL_CTRL),
1887 IOCTL_INFO_FNC(VIDIOC_G_TUNER, v4l_g_tuner, v4l_print_tuner, INFO_FL_CLEAR(v4l2_tuner, index)),
1888 IOCTL_INFO_FNC(VIDIOC_S_TUNER, v4l_s_tuner, v4l_print_tuner, INFO_FL_PRIO),
1889 IOCTL_INFO_STD(VIDIOC_G_AUDIO, vidioc_g_audio, v4l_print_audio, 0),
1890 IOCTL_INFO_STD(VIDIOC_S_AUDIO, vidioc_s_audio, v4l_print_audio, INFO_FL_PRIO),
1891 IOCTL_INFO_FNC(VIDIOC_QUERYCTRL, v4l_queryctrl, v4l_print_queryctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
1892 IOCTL_INFO_FNC(VIDIOC_QUERYMENU, v4l_querymenu, v4l_print_querymenu, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
1893 IOCTL_INFO_STD(VIDIOC_G_INPUT, vidioc_g_input, v4l_print_u32, 0),
1894 IOCTL_INFO_FNC(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO),
1895 IOCTL_INFO_STD(VIDIOC_G_OUTPUT, vidioc_g_output, v4l_print_u32, 0),
1896 IOCTL_INFO_FNC(VIDIOC_S_OUTPUT, v4l_s_output, v4l_print_u32, INFO_FL_PRIO),
1897 IOCTL_INFO_FNC(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)),
1898 IOCTL_INFO_STD(VIDIOC_G_AUDOUT, vidioc_g_audout, v4l_print_audioout, 0),
1899 IOCTL_INFO_STD(VIDIOC_S_AUDOUT, vidioc_s_audout, v4l_print_audioout, INFO_FL_PRIO),
1900 IOCTL_INFO_STD(VIDIOC_G_MODULATOR, vidioc_g_modulator, v4l_print_modulator, INFO_FL_CLEAR(v4l2_modulator, index)),
1901 IOCTL_INFO_STD(VIDIOC_S_MODULATOR, vidioc_s_modulator, v4l_print_modulator, INFO_FL_PRIO),
1902 IOCTL_INFO_FNC(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)),
1903 IOCTL_INFO_FNC(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO),
1904 IOCTL_INFO_FNC(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)),
1905 IOCTL_INFO_FNC(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)),
1906 IOCTL_INFO_FNC(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO),
1907 IOCTL_INFO_STD(VIDIOC_G_SELECTION, vidioc_g_selection, v4l_print_selection, 0),
1908 IOCTL_INFO_STD(VIDIOC_S_SELECTION, vidioc_s_selection, v4l_print_selection, INFO_FL_PRIO),
1909 IOCTL_INFO_STD(VIDIOC_G_JPEGCOMP, vidioc_g_jpegcomp, v4l_print_jpegcompression, 0),
1910 IOCTL_INFO_STD(VIDIOC_S_JPEGCOMP, vidioc_s_jpegcomp, v4l_print_jpegcompression, INFO_FL_PRIO),
1911 IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0),
1912 IOCTL_INFO_FNC(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0),
1913 IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)),
1914 IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
1915 IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0),
1916 IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO),
1917 IOCTL_INFO_FNC(VIDIOC_G_SLICED_VBI_CAP, v4l_g_sliced_vbi_cap, v4l_print_sliced_vbi_cap, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
1918 IOCTL_INFO_FNC(VIDIOC_LOG_STATUS, v4l_log_status, v4l_print_newline, 0),
1919 IOCTL_INFO_FNC(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL),
1920 IOCTL_INFO_FNC(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL),
1921 IOCTL_INFO_FNC(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, 0),
1922 IOCTL_INFO_STD(VIDIOC_ENUM_FRAMESIZES, vidioc_enum_framesizes, v4l_print_frmsizeenum, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
1923 IOCTL_INFO_STD(VIDIOC_ENUM_FRAMEINTERVALS, vidioc_enum_frameintervals, v4l_print_frmivalenum, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
1924 IOCTL_INFO_STD(VIDIOC_G_ENC_INDEX, vidioc_g_enc_index, v4l_print_enc_idx, 0),
1925 IOCTL_INFO_STD(VIDIOC_ENCODER_CMD, vidioc_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
1926 IOCTL_INFO_STD(VIDIOC_TRY_ENCODER_CMD, vidioc_try_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
1927 IOCTL_INFO_STD(VIDIOC_DECODER_CMD, vidioc_decoder_cmd, v4l_print_decoder_cmd, INFO_FL_PRIO),
1928 IOCTL_INFO_STD(VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd, v4l_print_decoder_cmd, 0),
1929 IOCTL_INFO_FNC(VIDIOC_DBG_S_REGISTER, v4l_dbg_s_register, v4l_print_dbg_register, 0),
1930 IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0),
1931 IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_IDENT, v4l_dbg_g_chip_ident, v4l_print_dbg_chip_ident, 0),
1932 IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO),
1933 IOCTL_INFO_STD(VIDIOC_ENUM_DV_PRESETS, vidioc_enum_dv_presets, v4l_print_dv_enum_presets, 0),
1934 IOCTL_INFO_STD(VIDIOC_S_DV_PRESET, vidioc_s_dv_preset, v4l_print_dv_preset, INFO_FL_PRIO),
1935 IOCTL_INFO_STD(VIDIOC_G_DV_PRESET, vidioc_g_dv_preset, v4l_print_dv_preset, 0),
1936 IOCTL_INFO_STD(VIDIOC_QUERY_DV_PRESET, vidioc_query_dv_preset, v4l_print_dv_preset, 0),
1937 IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO),
1938 IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0),
1939 IOCTL_INFO_FNC(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0),
1940 IOCTL_INFO_FNC(VIDIOC_SUBSCRIBE_EVENT, v4l_subscribe_event, v4l_print_event_subscription, 0),
1941 IOCTL_INFO_FNC(VIDIOC_UNSUBSCRIBE_EVENT, v4l_unsubscribe_event, v4l_print_event_subscription, 0),
1942 IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO),
1943 IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, 0),
1944 IOCTL_INFO_STD(VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings, v4l_print_enum_dv_timings, 0),
1945 IOCTL_INFO_STD(VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings, v4l_print_dv_timings, 0),
1946 IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, v4l_print_dv_timings_cap, 0),
1948 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
1950 bool v4l2_is_known_ioctl(unsigned int cmd)
1952 if (_IOC_NR(cmd) >= V4L2_IOCTLS)
1954 return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
1957 /* Common ioctl debug function. This function can be used by
1958 external ioctl messages as well as internal V4L ioctl */
1959 void v4l_printk_ioctl(unsigned int cmd)
1961 const char *dir, *type;
1963 switch (_IOC_TYPE(cmd)) {
1968 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
1972 pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
1979 switch (_IOC_DIR(cmd)) {
1980 case _IOC_NONE: dir = "--"; break;
1981 case _IOC_READ: dir = "r-"; break;
1982 case _IOC_WRITE: dir = "-w"; break;
1983 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
1984 default: dir = "*ERR*"; break;
1986 pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
1987 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
1989 EXPORT_SYMBOL(v4l_printk_ioctl);
1991 static long __video_do_ioctl(struct file *file,
1992 unsigned int cmd, void *arg)
1994 struct video_device *vfd = video_devdata(file);
1995 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
1996 bool write_only = false;
1997 struct v4l2_ioctl_info default_info;
1998 const struct v4l2_ioctl_info *info;
1999 void *fh = file->private_data;
2000 struct v4l2_fh *vfh = NULL;
2001 int use_fh_prio = 0;
2002 int debug = vfd->debug;
2006 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
2011 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
2012 vfh = file->private_data;
2013 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
2016 if (v4l2_is_known_ioctl(cmd)) {
2017 info = &v4l2_ioctls[_IOC_NR(cmd)];
2019 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
2020 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
2023 if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
2024 ret = v4l2_prio_check(vfd->prio, vfh->prio);
2029 default_info.ioctl = cmd;
2030 default_info.flags = 0;
2031 default_info.debug = v4l_print_default;
2032 info = &default_info;
2035 write_only = _IOC_DIR(cmd) == _IOC_WRITE;
2036 if (write_only && debug > V4L2_DEBUG_IOCTL) {
2037 v4l_print_ioctl(vfd->name, cmd);
2039 info->debug(arg, write_only);
2041 if (info->flags & INFO_FL_STD) {
2042 typedef int (*vidioc_op)(struct file *file, void *fh, void *p);
2043 const void *p = vfd->ioctl_ops;
2044 const vidioc_op *vidioc = p + info->offset;
2046 ret = (*vidioc)(file, fh, arg);
2047 } else if (info->flags & INFO_FL_FUNC) {
2048 ret = info->func(ops, file, fh, arg);
2049 } else if (!ops->vidioc_default) {
2052 ret = ops->vidioc_default(file, fh,
2053 use_fh_prio ? v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
2059 if (write_only && debug > V4L2_DEBUG_IOCTL) {
2061 printk(KERN_DEBUG "%s: error %ld\n",
2062 video_device_node_name(vfd), ret);
2065 v4l_print_ioctl(vfd->name, cmd);
2067 pr_cont(": error %ld\n", ret);
2068 else if (debug == V4L2_DEBUG_IOCTL)
2070 else if (_IOC_DIR(cmd) == _IOC_NONE)
2071 info->debug(arg, write_only);
2074 info->debug(arg, write_only);
2081 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2082 void * __user *user_ptr, void ***kernel_ptr)
2087 case VIDIOC_QUERYBUF:
2089 case VIDIOC_DQBUF: {
2090 struct v4l2_buffer *buf = parg;
2092 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2093 if (buf->length > VIDEO_MAX_PLANES) {
2097 *user_ptr = (void __user *)buf->m.planes;
2098 *kernel_ptr = (void *)&buf->m.planes;
2099 *array_size = sizeof(struct v4l2_plane) * buf->length;
2105 case VIDIOC_S_EXT_CTRLS:
2106 case VIDIOC_G_EXT_CTRLS:
2107 case VIDIOC_TRY_EXT_CTRLS: {
2108 struct v4l2_ext_controls *ctrls = parg;
2110 if (ctrls->count != 0) {
2111 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2115 *user_ptr = (void __user *)ctrls->controls;
2116 *kernel_ptr = (void *)&ctrls->controls;
2117 *array_size = sizeof(struct v4l2_ext_control)
2129 video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2134 void *parg = (void *)arg;
2136 bool has_array_args;
2137 size_t array_size = 0;
2138 void __user *user_ptr = NULL;
2139 void **kernel_ptr = NULL;
2141 /* Copy arguments into temp kernel buffer */
2142 if (_IOC_DIR(cmd) != _IOC_NONE) {
2143 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2146 /* too big to allocate from stack */
2147 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2154 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2155 unsigned int n = _IOC_SIZE(cmd);
2158 * In some cases, only a few fields are used as input,
2159 * i.e. when the app sets "index" and then the driver
2160 * fills in the rest of the structure for the thing
2161 * with that index. We only need to copy up the first
2164 if (v4l2_is_known_ioctl(cmd)) {
2165 u32 flags = v4l2_ioctls[_IOC_NR(cmd)].flags;
2166 if (flags & INFO_FL_CLEAR_MASK)
2167 n = (flags & INFO_FL_CLEAR_MASK) >> 16;
2170 if (copy_from_user(parg, (void __user *)arg, n))
2173 /* zero out anything we don't copy from userspace */
2174 if (n < _IOC_SIZE(cmd))
2175 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
2177 /* read-only ioctl */
2178 memset(parg, 0, _IOC_SIZE(cmd));
2182 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2185 has_array_args = err;
2187 if (has_array_args) {
2189 * When adding new types of array args, make sure that the
2190 * parent argument to ioctl (which contains the pointer to the
2191 * array) fits into sbuf (so that mbuf will still remain
2192 * unused up to here).
2194 mbuf = kmalloc(array_size, GFP_KERNEL);
2197 goto out_array_args;
2199 if (copy_from_user(mbuf, user_ptr, array_size))
2200 goto out_array_args;
2205 err = func(file, cmd, parg);
2206 if (err == -ENOIOCTLCMD)
2209 if (has_array_args) {
2210 *kernel_ptr = user_ptr;
2211 if (copy_to_user(user_ptr, mbuf, array_size))
2213 goto out_array_args;
2215 /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid
2216 results that must be returned. */
2217 if (err < 0 && cmd != VIDIOC_QUERY_DV_TIMINGS)
2221 /* Copy results into user buffer */
2222 switch (_IOC_DIR(cmd)) {
2224 case (_IOC_WRITE | _IOC_READ):
2225 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2234 EXPORT_SYMBOL(video_usercopy);
2236 long video_ioctl2(struct file *file,
2237 unsigned int cmd, unsigned long arg)
2239 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2241 EXPORT_SYMBOL(video_ioctl2);