4 * A generic video device interface for the LINUX operating system
5 * using a set of device structures/vectors for low level operations.
7 * This file replaces the videodev.c file that comes with the
8 * regular kernel distribution.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
15 * Author: Bill Dirks <bdirks@pacbell.net>
16 * based on code by Alan Cox, <alan@cymru.net>
21 * Video capture interface for Linux
23 * A generic video device interface for the LINUX operating system
24 * using a set of device structures/vectors for low level operations.
26 * This program is free software; you can redistribute it and/or
27 * modify it under the terms of the GNU General Public License
28 * as published by the Free Software Foundation; either version
29 * 2 of the License, or (at your option) any later version.
31 * Author: Alan Cox, <alan@redhat.com>
37 * Video4linux 1/2 integration by Justin Schoeman
38 * <justin@suntiger.ee.up.ac.za>
39 * 2.4 PROCFS support ported from 2.4 kernels by
40 * Iñaki García Etxebarria <garetxe@euskalnet.net>
41 * Makefile fix by "W. Michael Petullo" <mike@flyn.org>
42 * 2.4 devfs support ported from 2.4 kernels by
43 * Dan Merillat <dan@merillat.org>
44 * Added Gerd Knorrs v4l1 enhancements (Justin Schoeman)
47 #include <linux/module.h>
48 #include <linux/types.h>
49 #include <linux/kernel.h>
50 #include <linux/sched.h>
51 #include <linux/smp_lock.h>
53 #include <linux/string.h>
54 #include <linux/errno.h>
55 #include <asm/uaccess.h>
56 #include <asm/system.h>
57 #include <asm/pgtable.h>
59 #include <asm/div64.h>
60 #include <linux/video_decoder.h>
61 #define __OLD_VIDIOC_ /* To allow fixing old calls*/
62 #include <media/v4l2-common.h>
65 #include <linux/kmod.h>
68 #if defined(CONFIG_UST) || defined(CONFIG_UST_MODULE)
69 #include <linux/ust.h>
73 #include <linux/videodev.h>
75 MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
76 MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers");
77 MODULE_LICENSE("GPL");
81 * V 4 L 2 D R I V E R H E L P E R A P I
86 * Video Standard Operations (contributed by Michael Schimek)
90 /* Fill in the fields of a v4l2_standard structure according to the
91 'id' and 'transmission' parameters. Returns negative on error. */
92 int v4l2_video_std_construct(struct v4l2_standard *vs,
95 u32 index = vs->index;
97 memset(vs, 0, sizeof(struct v4l2_standard));
100 if (id & V4L2_STD_525_60) {
101 vs->frameperiod.numerator = 1001;
102 vs->frameperiod.denominator = 30000;
103 vs->framelines = 525;
105 vs->frameperiod.numerator = 1;
106 vs->frameperiod.denominator = 25;
107 vs->framelines = 625;
109 strlcpy(vs->name,name,sizeof(vs->name));
113 /* ----------------------------------------------------------------- */
114 /* priority handling */
116 #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND || \
117 val == V4L2_PRIORITY_INTERACTIVE || \
118 val == V4L2_PRIORITY_RECORD)
120 int v4l2_prio_init(struct v4l2_prio_state *global)
122 memset(global,0,sizeof(*global));
126 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
127 enum v4l2_priority new)
129 if (!V4L2_PRIO_VALID(new))
134 atomic_inc(&global->prios[new]);
135 if (V4L2_PRIO_VALID(*local))
136 atomic_dec(&global->prios[*local]);
141 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
143 return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
146 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
148 if (V4L2_PRIO_VALID(*local))
149 atomic_dec(&global->prios[*local]);
153 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
155 if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
156 return V4L2_PRIORITY_RECORD;
157 if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
158 return V4L2_PRIORITY_INTERACTIVE;
159 if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
160 return V4L2_PRIORITY_BACKGROUND;
161 return V4L2_PRIORITY_UNSET;
164 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
166 if (*local < v4l2_prio_max(global))
172 /* ----------------------------------------------------------------- */
173 /* some arrays for pretty-printing debug messages of enum types */
175 char *v4l2_field_names[] = {
176 [V4L2_FIELD_ANY] = "any",
177 [V4L2_FIELD_NONE] = "none",
178 [V4L2_FIELD_TOP] = "top",
179 [V4L2_FIELD_BOTTOM] = "bottom",
180 [V4L2_FIELD_INTERLACED] = "interlaced",
181 [V4L2_FIELD_SEQ_TB] = "seq-tb",
182 [V4L2_FIELD_SEQ_BT] = "seq-bt",
183 [V4L2_FIELD_ALTERNATE] = "alternate",
186 char *v4l2_type_names[] = {
187 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
188 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
189 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
190 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
191 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
192 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
193 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "slicec-vbi-out",
196 static char *v4l2_memory_names[] = {
197 [V4L2_MEMORY_MMAP] = "mmap",
198 [V4L2_MEMORY_USERPTR] = "userptr",
199 [V4L2_MEMORY_OVERLAY] = "overlay",
202 #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
204 /* ------------------------------------------------------------------ */
205 /* debug help functions */
207 #ifdef CONFIG_VIDEO_V4L1_COMPAT
208 static const char *v4l1_ioctls[] = {
209 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
210 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
211 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
212 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
213 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
214 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
215 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
216 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
217 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
218 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
219 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
220 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
221 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
222 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
223 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
224 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
225 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
226 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
227 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
228 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
229 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
230 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
231 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
232 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
233 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
234 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
235 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
236 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
237 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
239 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
242 static const char *v4l2_ioctls[] = {
243 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
244 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
245 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
246 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
247 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
248 [_IOC_NR(VIDIOC_G_MPEGCOMP)] = "VIDIOC_G_MPEGCOMP",
249 [_IOC_NR(VIDIOC_S_MPEGCOMP)] = "VIDIOC_S_MPEGCOMP",
250 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
251 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
252 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
253 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
254 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
255 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
256 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
257 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
258 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
259 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
260 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
261 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
262 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
263 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
264 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
265 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
266 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
267 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
268 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
269 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
270 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
271 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
272 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
273 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
274 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
275 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
276 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
277 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
278 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
279 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
280 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
281 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
282 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
283 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
284 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
285 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
286 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
287 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
288 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
289 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
290 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
291 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
292 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
293 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
294 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
296 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
298 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
299 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
300 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
301 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS"
303 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
305 static const char *v4l2_int_ioctls[] = {
306 #ifdef CONFIG_VIDEO_V4L1_COMPAT
307 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
308 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
309 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
310 [_IOC_NR(DECODER_SET_INPUT)] = "DECODER_SET_INPUT",
311 [_IOC_NR(DECODER_SET_OUTPUT)] = "DECODER_SET_OUTPUT",
312 [_IOC_NR(DECODER_ENABLE_OUTPUT)] = "DECODER_ENABLE_OUTPUT",
313 [_IOC_NR(DECODER_SET_PICTURE)] = "DECODER_SET_PICTURE",
314 [_IOC_NR(DECODER_SET_GPIO)] = "DECODER_SET_GPIO",
315 [_IOC_NR(DECODER_INIT)] = "DECODER_INIT",
316 [_IOC_NR(DECODER_SET_VBI_BYPASS)] = "DECODER_SET_VBI_BYPASS",
317 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
319 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
321 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
322 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
323 [_IOC_NR(TDA9887_SET_CONFIG)] = "TDA9887_SET_CONFIG",
325 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
326 [_IOC_NR(VIDIOC_INT_S_REGISTER)] = "VIDIOC_INT_S_REGISTER",
327 [_IOC_NR(VIDIOC_INT_G_REGISTER)] = "VIDIOC_INT_G_REGISTER",
328 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
329 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
330 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
331 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
332 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
333 [_IOC_NR(VIDIOC_INT_G_CHIP_IDENT)] = "VIDIOC_INT_G_CHIP_IDENT",
334 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
335 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
336 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
337 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
338 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
339 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
340 [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ"
342 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
344 static void v4l_print_pix_fmt (char *s, struct v4l2_pix_format *fmt)
346 printk ("%s: width=%d, height=%d, format=%d, field=%s, "
347 "bytesperline=%d sizeimage=%d, colorspace=%d\n", s,
348 fmt->width,fmt->height,fmt->pixelformat,
349 prt_names(fmt->field,v4l2_field_names),
350 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
353 /* Common ioctl debug function. This function can be used by
354 external ioctl messages as well as internal V4L ioctl */
355 void v4l_printk_ioctl(unsigned int cmd)
359 switch (_IOC_DIR(cmd)) {
360 case _IOC_NONE: dir = "--"; break;
361 case _IOC_READ: dir = "r-"; break;
362 case _IOC_WRITE: dir = "-w"; break;
363 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
364 default: dir = "*ERR*"; break;
366 switch (_IOC_TYPE(cmd)) {
368 printk("v4l2_int ioctl %s, dir=%s (0x%08x)\n",
369 (_IOC_NR(cmd) < V4L2_INT_IOCTLS) ?
370 v4l2_int_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
372 #ifdef CONFIG_VIDEO_V4L1_COMPAT
374 printk("v4l1 ioctl %s, dir=%s (0x%08x)\n",
375 (_IOC_NR(cmd) < V4L1_IOCTLS) ?
376 v4l1_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
380 printk("v4l2 ioctl %s, dir=%s (0x%08x)\n",
381 (_IOC_NR(cmd) < V4L2_IOCTLS) ?
382 v4l2_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
386 printk("unknown ioctl '%c', dir=%s, #%d (0x%08x)\n",
387 _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
391 /* Common ioctl debug function. This function can be used by
392 external ioctl messages as well as internal V4L ioctl and its
394 void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
398 v4l_printk_ioctl(cmd);
400 case VIDIOC_INT_G_CHIP_IDENT:
402 enum v4l2_chip_ident *p=arg;
403 printk ("%s: chip ident=%d\n", s, *p);
406 case VIDIOC_G_PRIORITY:
407 case VIDIOC_S_PRIORITY:
409 enum v4l2_priority *p=arg;
410 printk ("%s: priority=%d\n", s, *p);
413 case VIDIOC_INT_S_TUNER_MODE:
415 enum v4l2_tuner_type *p=arg;
416 printk ("%s: tuner type=%d\n", s, *p);
419 #ifdef CONFIG_VIDEO_V4L1_COMPAT
420 case DECODER_SET_VBI_BYPASS:
421 case DECODER_ENABLE_OUTPUT:
422 case DECODER_GET_STATUS:
423 case DECODER_SET_OUTPUT:
424 case DECODER_SET_INPUT:
425 case DECODER_SET_GPIO:
426 case DECODER_SET_NORM:
429 case VIDIOCSWRITEMODE:
431 case TUNER_SET_TYPE_ADDR:
432 case TUNER_SET_STANDBY:
433 case TDA9887_SET_CONFIG:
435 case VIDIOC_OVERLAY_OLD:
437 case VIDIOC_STREAMOFF:
438 case VIDIOC_G_OUTPUT:
439 case VIDIOC_S_OUTPUT:
440 case VIDIOC_STREAMON:
446 printk ("%s: value=%d\n", s, *p);
451 case VIDIOC_ENUMAUDIO:
453 case VIDIOC_G_AUDIO_OLD:
456 struct v4l2_audio *p=arg;
458 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n",
459 s,p->index, p->name,p->capability, p->mode);
462 case VIDIOC_G_AUDOUT:
463 case VIDIOC_S_AUDOUT:
464 case VIDIOC_ENUMAUDOUT:
466 case VIDIOC_G_AUDOUT_OLD:
469 struct v4l2_audioout *p=arg;
470 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n", s,
471 p->index, p->name, p->capability,p->mode);
476 case VIDIOC_QUERYBUF:
478 struct v4l2_buffer *p=arg;
479 struct v4l2_timecode *tc=&p->timecode;
480 printk ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, "
481 "bytesused=%d, flags=0x%08x, "
482 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n",
484 (p->timestamp.tv_sec/3600),
485 (int)(p->timestamp.tv_sec/60)%60,
486 (int)(p->timestamp.tv_sec%60),
487 p->timestamp.tv_usec,
489 prt_names(p->type,v4l2_type_names),
490 p->bytesused,p->flags,
491 p->field,p->sequence,
492 prt_names(p->memory,v4l2_memory_names),
494 printk ("%s: timecode= %02d:%02d:%02d type=%d, "
495 "flags=0x%08x, frames=%d, userbits=0x%08x\n",
496 s,tc->hours,tc->minutes,tc->seconds,
497 tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
500 case VIDIOC_QUERYCAP:
502 struct v4l2_capability *p=arg;
503 printk ("%s: driver=%s, card=%s, bus=%s, version=0x%08x, "
504 "capabilities=0x%08x\n", s,
505 p->driver,p->card,p->bus_info,
513 case VIDIOC_S_CTRL_OLD:
516 struct v4l2_control *p=arg;
517 printk ("%s: id=%d, value=%d\n", s, p->id, p->value);
520 case VIDIOC_G_EXT_CTRLS:
521 case VIDIOC_S_EXT_CTRLS:
522 case VIDIOC_TRY_EXT_CTRLS:
524 struct v4l2_ext_controls *p = arg;
527 printk("%s: ctrl_class=%d, count=%d\n", s, p->ctrl_class, p->count);
528 for (i = 0; i < p->count; i++) {
529 struct v4l2_ext_control *c = &p->controls[i];
530 if (cmd == VIDIOC_G_EXT_CTRLS)
531 printk("%s: id=%d\n", s, c->id);
533 printk("%s: id=%d, value=%d\n", s, c->id, c->value);
540 struct v4l2_crop *p=arg;
541 /*FIXME: Should also show rect structs */
542 printk ("%s: type=%d\n", s, p->type);
547 case VIDIOC_CROPCAP_OLD:
550 struct v4l2_cropcap *p=arg;
551 /*FIXME: Should also show rect structs */
552 printk ("%s: type=%d\n", s, p->type);
555 case VIDIOC_INT_DECODE_VBI_LINE:
557 struct v4l2_decode_vbi_line *p=arg;
558 printk ("%s: is_second_field=%d, ptr=0x%08lx, line=%d, "
560 p->is_second_field,(unsigned long)p->p,p->line,p->type);
563 case VIDIOC_ENUM_FMT:
565 struct v4l2_fmtdesc *p=arg;
566 printk ("%s: index=%d, type=%d, flags=%d, description=%s,"
567 " pixelformat=%d\n", s,
568 p->index, p->type, p->flags,p->description,
577 struct v4l2_format *p=arg;
578 printk ("%s: type=%s\n", s,
579 prt_names(p->type,v4l2_type_names));
581 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
582 v4l_print_pix_fmt (s, &p->fmt.pix);
591 struct v4l2_framebuffer *p=arg;
592 printk ("%s: capability=%d, flags=%d, base=0x%08lx\n", s,
593 p->capability,p->flags, (unsigned long)p->base);
594 v4l_print_pix_fmt (s, &p->fmt);
597 case VIDIOC_G_FREQUENCY:
598 case VIDIOC_S_FREQUENCY:
600 struct v4l2_frequency *p=arg;
601 printk ("%s: tuner=%d, type=%d, frequency=%d\n", s,
602 p->tuner,p->type,p->frequency);
605 case VIDIOC_ENUMINPUT:
607 struct v4l2_input *p=arg;
608 printk ("%s: index=%d, name=%s, type=%d, audioset=%d, "
609 "tuner=%d, std=%Ld, status=%d\n", s,
610 p->index,p->name,p->type,p->audioset,
612 (unsigned long long)p->std,
616 case VIDIOC_G_JPEGCOMP:
617 case VIDIOC_S_JPEGCOMP:
619 struct v4l2_jpegcompression *p=arg;
620 printk ("%s: quality=%d, APPn=%d, APP_len=%d, COM_len=%d,"
621 " jpeg_markers=%d\n", s,
622 p->quality,p->APPn,p->APP_len,
623 p->COM_len,p->jpeg_markers);
626 case VIDIOC_G_MODULATOR:
627 case VIDIOC_S_MODULATOR:
629 struct v4l2_modulator *p=arg;
630 printk ("%s: index=%d, name=%s, capability=%d, rangelow=%d,"
631 " rangehigh=%d, txsubchans=%d\n", s,
632 p->index, p->name,p->capability,p->rangelow,
633 p->rangehigh,p->txsubchans);
636 case VIDIOC_G_MPEGCOMP:
637 case VIDIOC_S_MPEGCOMP:
639 struct v4l2_mpeg_compression *p=arg;
640 /*FIXME: Several fields not shown */
641 printk ("%s: ts_pid_pmt=%d, ts_pid_audio=%d, ts_pid_video=%d, "
642 "ts_pid_pcr=%d, ps_size=%d, au_sample_rate=%d, "
643 "au_pesid=%c, vi_frame_rate=%d, vi_frames_per_gop=%d, "
644 "vi_bframes_count=%d, vi_pesid=%c\n", s,
645 p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
646 p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
647 p->au_pesid, p->vi_frame_rate,
648 p->vi_frames_per_gop, p->vi_bframes_count,
652 case VIDIOC_ENUMOUTPUT:
654 struct v4l2_output *p=arg;
655 printk ("%s: index=%d, name=%s,type=%d, audioset=%d, "
656 "modulator=%d, std=%Ld\n",
657 s,p->index,p->name,p->type,p->audioset,
659 (unsigned long long)p->std);
662 case VIDIOC_QUERYCTRL:
664 struct v4l2_queryctrl *p=arg;
665 printk ("%s: id=%d, type=%d, name=%s, min/max=%d/%d,"
666 " step=%d, default=%d, flags=0x%08x\n", s,
667 p->id,p->type,p->name,p->minimum,p->maximum,
668 p->step,p->default_value,p->flags);
671 case VIDIOC_QUERYMENU:
673 struct v4l2_querymenu *p=arg;
674 printk ("%s: id=%d, index=%d, name=%s\n", s,
675 p->id,p->index,p->name);
678 case VIDIOC_INT_G_REGISTER:
679 case VIDIOC_INT_S_REGISTER:
681 struct v4l2_register *p=arg;
682 printk ("%s: i2c_id=%d, reg=%lu, val=%d\n", s,
683 p->i2c_id,p->reg,p->val);
689 struct v4l2_requestbuffers *p=arg;
690 printk ("%s: count=%d, type=%s, memory=%s\n", s,
692 prt_names(p->type,v4l2_type_names),
693 prt_names(p->memory,v4l2_memory_names));
696 case VIDIOC_INT_S_AUDIO_ROUTING:
697 case VIDIOC_INT_S_VIDEO_ROUTING:
698 case VIDIOC_INT_G_AUDIO_ROUTING:
699 case VIDIOC_INT_G_VIDEO_ROUTING:
701 struct v4l2_routing *p=arg;
702 printk ("%s: input=0x%x, output=0x%x\n", s, p->input, p->output);
705 case VIDIOC_INT_S_CRYSTAL_FREQ:
707 struct v4l2_crystal_freq *p=arg;
708 printk ("%s: freq=%u, flags=0x%x\n", s, p->freq, p->flags);
711 case VIDIOC_G_SLICED_VBI_CAP:
713 struct v4l2_sliced_vbi_cap *p=arg;
714 printk ("%s: service_set=%d\n", s,
718 case VIDIOC_INT_S_VBI_DATA:
719 case VIDIOC_INT_G_VBI_DATA:
721 struct v4l2_sliced_vbi_data *p=arg;
722 printk ("%s: id=%d, field=%d, line=%d\n", s,
723 p->id, p->field, p->line);
728 struct v4l2_standard *p=arg;
729 printk ("%s: index=%d, id=%Ld, name=%s, fps=%d/%d, "
730 "framelines=%d\n", s, p->index,
731 (unsigned long long)p->id, p->name,
732 p->frameperiod.numerator,
733 p->frameperiod.denominator,
741 case VIDIOC_S_PARM_OLD:
744 struct v4l2_streamparm *p=arg;
745 printk ("%s: type=%d\n", s, p->type);
752 struct v4l2_tuner *p=arg;
753 printk ("%s: index=%d, name=%s, type=%d, capability=%d, "
754 "rangelow=%d, rangehigh=%d, signal=%d, afc=%d, "
755 "rxsubchans=%d, audmode=%d\n", s,
756 p->index, p->name, p->type,
757 p->capability, p->rangelow,p->rangehigh,
758 p->rxsubchans, p->audmode, p->signal,
762 #ifdef CONFIG_VIDEO_V4L1_COMPAT
766 struct vbi_format *p=arg;
767 printk ("%s: sampling_rate=%d, samples_per_line=%d, "
768 "sample_format=%d, start=%d/%d, count=%d/%d, flags=%d\n", s,
769 p->sampling_rate,p->samples_per_line,
770 p->sample_format,p->start[0],p->start[1],
771 p->count[0],p->count[1],p->flags);
777 struct video_audio *p=arg;
778 printk ("%s: audio=%d, volume=%d, bass=%d, treble=%d, "
779 "flags=%d, name=%s, mode=%d, balance=%d, step=%d\n",
780 s,p->audio,p->volume,p->bass, p->treble,
781 p->flags,p->name,p->mode,p->balance,p->step);
787 struct video_buffer *p=arg;
788 printk ("%s: base=%08lx, height=%d, width=%d, depth=%d, "
789 "bytesperline=%d\n", s,
790 (unsigned long) p->base, p->height, p->width,
791 p->depth,p->bytesperline);
796 struct video_capability *p=arg;
797 printk ("%s: name=%s, type=%d, channels=%d, audios=%d, "
798 "maxwidth=%d, maxheight=%d, minwidth=%d, minheight=%d\n",
799 s,p->name,p->type,p->channels,p->audios,
800 p->maxwidth,p->maxheight,p->minwidth,
808 struct video_capture *p=arg;
809 printk ("%s: x=%d, y=%d, width=%d, height=%d, decimation=%d,"
811 p->x, p->y,p->width, p->height,
812 p->decimation,p->flags);
818 struct video_channel *p=arg;
819 printk ("%s: channel=%d, name=%s, tuners=%d, flags=%d, "
820 "type=%d, norm=%d\n", s,
821 p->channel,p->name,p->tuners,
822 p->flags,p->type,p->norm);
826 case VIDIOCSMICROCODE:
828 struct video_code *p=arg;
829 printk ("%s: loadwhat=%s, datasize=%d\n", s,
830 p->loadwhat,p->datasize);
833 case DECODER_GET_CAPABILITIES:
835 struct video_decoder_capability *p=arg;
836 printk ("%s: flags=%d, inputs=%d, outputs=%d\n", s,
837 p->flags,p->inputs,p->outputs);
842 struct video_decoder_init *p=arg;
843 printk ("%s: len=%c\n", s, p->len);
846 case VIDIOCGPLAYINFO:
848 struct video_info *p=arg;
849 printk ("%s: frame_count=%d, h_size=%d, v_size=%d, "
850 "smpte_timecode=%d, picture_type=%d, "
851 "temporal_reference=%d, user_data=%s\n", s,
852 p->frame_count, p->h_size,
853 p->v_size, p->smpte_timecode,
854 p->picture_type, p->temporal_reference,
860 struct video_key *p=arg;
861 printk ("%s: key=%s, flags=%d\n", s,
867 struct video_mbuf *p=arg;
868 printk ("%s: size=%d, frames=%d, offsets=0x%08lx\n", s,
871 (unsigned long)p->offsets);
876 struct video_mmap *p=arg;
877 printk ("%s: frame=%d, height=%d, width=%d, format=%d\n", s,
885 case DECODER_SET_PICTURE:
887 struct video_picture *p=arg;
889 printk ("%s: brightness=%d, hue=%d, colour=%d, contrast=%d,"
890 " whiteness=%d, depth=%d, palette=%d\n", s,
891 p->brightness, p->hue, p->colour,
892 p->contrast, p->whiteness, p->depth,
896 case VIDIOCSPLAYMODE:
898 struct video_play_mode *p=arg;
899 printk ("%s: mode=%d, p1=%d, p2=%d\n", s,
900 p->mode,p->p1,p->p2);
906 struct video_tuner *p=arg;
907 printk ("%s: tuner=%d, name=%s, rangelow=%ld, rangehigh=%ld, "
908 "flags=%d, mode=%d, signal=%d\n", s,
909 p->tuner, p->name,p->rangelow, p->rangehigh,
910 p->flags,p->mode, p->signal);
915 struct video_unit *p=arg;
916 printk ("%s: video=%d, vbi=%d, radio=%d, audio=%d, "
918 p->video,p->vbi,p->radio,p->audio,p->teletext);
924 struct video_window *p=arg;
925 printk ("%s: x=%d, y=%d, width=%d, height=%d, chromakey=%d,"
926 " flags=%d, clipcount=%d\n", s,
927 p->x, p->y,p->width, p->height,
928 p->chromakey,p->flags,
935 unsigned long *p=arg;
936 printk ("%s: value=%lu\n", s, *p);
940 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
941 case VIDIOC_INT_I2S_CLOCK_FREQ:
942 case VIDIOC_INT_S_STANDBY:
943 case VIDIOC_INT_RESET:
947 printk ("%s: value=%d\n", s, *p);
952 case VIDIOC_QUERYSTD:
956 printk ("%s: value=%Lu\n", s, (unsigned long long)*p);
962 /* ----------------------------------------------------------------- */
964 /* Helper functions for control handling */
966 /* Check for correctness of the ctrl's value based on the data from
967 struct v4l2_queryctrl and the available menu items. Note that
968 menu_items may be NULL, in that case it is ignored. */
969 int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
970 const char **menu_items)
972 if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED)
974 if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED)
976 if (qctrl->type == V4L2_CTRL_TYPE_BUTTON ||
977 qctrl->type == V4L2_CTRL_TYPE_INTEGER64 ||
978 qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
980 if (ctrl->value < qctrl->minimum || ctrl->value > qctrl->maximum)
982 if (qctrl->type == V4L2_CTRL_TYPE_MENU && menu_items != NULL) {
983 if (menu_items[ctrl->value] == NULL ||
984 menu_items[ctrl->value][0] == '\0')
990 /* Returns NULL or a character pointer array containing the menu for
991 the given control ID. The pointer array ends with a NULL pointer.
992 An empty string signifies a menu entry that is invalid. This allows
993 drivers to disable certain options if it is not supported. */
994 const char **v4l2_ctrl_get_menu(u32 id)
996 static const char *mpeg_audio_sampling_freq[] = {
1002 static const char *mpeg_audio_encoding[] = {
1008 static const char *mpeg_audio_l1_bitrate[] = {
1025 static const char *mpeg_audio_l2_bitrate[] = {
1042 static const char *mpeg_audio_l3_bitrate[] = {
1059 static const char *mpeg_audio_mode[] = {
1066 static const char *mpeg_audio_mode_extension[] = {
1073 static const char *mpeg_audio_emphasis[] = {
1079 static const char *mpeg_audio_crc[] = {
1084 static const char *mpeg_video_encoding[] = {
1089 static const char *mpeg_video_aspect[] = {
1096 static const char *mpeg_video_bitrate_mode[] = {
1101 static const char *mpeg_stream_type[] = {
1102 "MPEG-2 Program Stream",
1103 "MPEG-2 Transport Stream",
1104 "MPEG-1 System Stream",
1105 "MPEG-2 DVD-compatible Stream",
1106 "MPEG-1 VCD-compatible Stream",
1107 "MPEG-2 SVCD-compatible Stream",
1110 static const char *mpeg_stream_vbi_fmt[] = {
1112 "Private packet, IVTV format",
1117 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1118 return mpeg_audio_sampling_freq;
1119 case V4L2_CID_MPEG_AUDIO_ENCODING:
1120 return mpeg_audio_encoding;
1121 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
1122 return mpeg_audio_l1_bitrate;
1123 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
1124 return mpeg_audio_l2_bitrate;
1125 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
1126 return mpeg_audio_l3_bitrate;
1127 case V4L2_CID_MPEG_AUDIO_MODE:
1128 return mpeg_audio_mode;
1129 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
1130 return mpeg_audio_mode_extension;
1131 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
1132 return mpeg_audio_emphasis;
1133 case V4L2_CID_MPEG_AUDIO_CRC:
1134 return mpeg_audio_crc;
1135 case V4L2_CID_MPEG_VIDEO_ENCODING:
1136 return mpeg_video_encoding;
1137 case V4L2_CID_MPEG_VIDEO_ASPECT:
1138 return mpeg_video_aspect;
1139 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1140 return mpeg_video_bitrate_mode;
1141 case V4L2_CID_MPEG_STREAM_TYPE:
1142 return mpeg_stream_type;
1143 case V4L2_CID_MPEG_STREAM_VBI_FMT:
1144 return mpeg_stream_vbi_fmt;
1150 /* Fill in a struct v4l2_queryctrl */
1151 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
1156 switch (qctrl->id) {
1158 case V4L2_CID_USER_CLASS: name = "User Controls"; break;
1159 case V4L2_CID_AUDIO_VOLUME: name = "Volume"; break;
1160 case V4L2_CID_AUDIO_MUTE: name = "Mute"; break;
1161 case V4L2_CID_AUDIO_BALANCE: name = "Balance"; break;
1162 case V4L2_CID_AUDIO_BASS: name = "Bass"; break;
1163 case V4L2_CID_AUDIO_TREBLE: name = "Treble"; break;
1164 case V4L2_CID_AUDIO_LOUDNESS: name = "Loudness"; break;
1165 case V4L2_CID_BRIGHTNESS: name = "Brightness"; break;
1166 case V4L2_CID_CONTRAST: name = "Contrast"; break;
1167 case V4L2_CID_SATURATION: name = "Saturation"; break;
1168 case V4L2_CID_HUE: name = "Hue"; break;
1171 case V4L2_CID_MPEG_CLASS: name = "MPEG Encoder Controls"; break;
1172 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: name = "Audio Sampling Frequency"; break;
1173 case V4L2_CID_MPEG_AUDIO_ENCODING: name = "Audio Encoding Layer"; break;
1174 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: name = "Audio Layer I Bitrate"; break;
1175 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: name = "Audio Layer II Bitrate"; break;
1176 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: name = "Audio Layer III Bitrate"; break;
1177 case V4L2_CID_MPEG_AUDIO_MODE: name = "Audio Stereo Mode"; break;
1178 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: name = "Audio Stereo Mode Extension"; break;
1179 case V4L2_CID_MPEG_AUDIO_EMPHASIS: name = "Audio Emphasis"; break;
1180 case V4L2_CID_MPEG_AUDIO_CRC: name = "Audio CRC"; break;
1181 case V4L2_CID_MPEG_VIDEO_ENCODING: name = "Video Encoding"; break;
1182 case V4L2_CID_MPEG_VIDEO_ASPECT: name = "Video Aspect"; break;
1183 case V4L2_CID_MPEG_VIDEO_B_FRAMES: name = "Video B Frames"; break;
1184 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: name = "Video GOP Size"; break;
1185 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: name = "Video GOP Closure"; break;
1186 case V4L2_CID_MPEG_VIDEO_PULLDOWN: name = "Video Pulldown"; break;
1187 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: name = "Video Bitrate Mode"; break;
1188 case V4L2_CID_MPEG_VIDEO_BITRATE: name = "Video Bitrate"; break;
1189 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: name = "Video Peak Bitrate"; break;
1190 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: name = "Video Temporal Decimation"; break;
1191 case V4L2_CID_MPEG_STREAM_TYPE: name = "Stream Type"; break;
1192 case V4L2_CID_MPEG_STREAM_PID_PMT: name = "Stream PMT Program ID"; break;
1193 case V4L2_CID_MPEG_STREAM_PID_AUDIO: name = "Stream Audio Program ID"; break;
1194 case V4L2_CID_MPEG_STREAM_PID_VIDEO: name = "Stream Video Program ID"; break;
1195 case V4L2_CID_MPEG_STREAM_PID_PCR: name = "Stream PCR Program ID"; break;
1196 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: name = "Stream PES Audio ID"; break;
1197 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: name = "Stream PES Video ID"; break;
1198 case V4L2_CID_MPEG_STREAM_VBI_FMT: name = "Stream VBI Format"; break;
1203 switch (qctrl->id) {
1204 case V4L2_CID_AUDIO_MUTE:
1205 case V4L2_CID_AUDIO_LOUDNESS:
1206 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
1207 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
1208 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
1212 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1213 case V4L2_CID_MPEG_AUDIO_ENCODING:
1214 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
1215 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
1216 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
1217 case V4L2_CID_MPEG_AUDIO_MODE:
1218 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
1219 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
1220 case V4L2_CID_MPEG_AUDIO_CRC:
1221 case V4L2_CID_MPEG_VIDEO_ENCODING:
1222 case V4L2_CID_MPEG_VIDEO_ASPECT:
1223 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1224 case V4L2_CID_MPEG_STREAM_TYPE:
1225 case V4L2_CID_MPEG_STREAM_VBI_FMT:
1226 qctrl->type = V4L2_CTRL_TYPE_MENU;
1229 case V4L2_CID_USER_CLASS:
1230 case V4L2_CID_MPEG_CLASS:
1231 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
1232 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1233 min = max = step = def = 0;
1236 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
1239 switch (qctrl->id) {
1240 case V4L2_CID_MPEG_AUDIO_ENCODING:
1241 case V4L2_CID_MPEG_AUDIO_MODE:
1242 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1243 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
1244 case V4L2_CID_MPEG_STREAM_TYPE:
1245 qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
1247 case V4L2_CID_AUDIO_VOLUME:
1248 case V4L2_CID_AUDIO_BALANCE:
1249 case V4L2_CID_AUDIO_BASS:
1250 case V4L2_CID_AUDIO_TREBLE:
1251 case V4L2_CID_BRIGHTNESS:
1252 case V4L2_CID_CONTRAST:
1253 case V4L2_CID_SATURATION:
1255 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
1258 qctrl->minimum = min;
1259 qctrl->maximum = max;
1261 qctrl->default_value = def;
1262 qctrl->reserved[0] = qctrl->reserved[1] = 0;
1263 snprintf(qctrl->name, sizeof(qctrl->name), name);
1267 /* Fill in a struct v4l2_queryctrl with standard values based on
1269 int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
1271 switch (qctrl->id) {
1273 case V4L2_CID_USER_CLASS:
1274 case V4L2_CID_MPEG_CLASS:
1275 return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0);
1276 case V4L2_CID_AUDIO_VOLUME:
1277 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 58880);
1278 case V4L2_CID_AUDIO_MUTE:
1279 case V4L2_CID_AUDIO_LOUDNESS:
1280 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
1281 case V4L2_CID_AUDIO_BALANCE:
1282 case V4L2_CID_AUDIO_BASS:
1283 case V4L2_CID_AUDIO_TREBLE:
1284 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 32768);
1285 case V4L2_CID_BRIGHTNESS:
1286 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
1287 case V4L2_CID_CONTRAST:
1288 case V4L2_CID_SATURATION:
1289 return v4l2_ctrl_query_fill(qctrl, 0, 127, 1, 64);
1291 return v4l2_ctrl_query_fill(qctrl, -128, 127, 1, 0);
1294 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1295 return v4l2_ctrl_query_fill(qctrl,
1296 V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100,
1297 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 1,
1298 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
1299 case V4L2_CID_MPEG_AUDIO_ENCODING:
1300 return v4l2_ctrl_query_fill(qctrl,
1301 V4L2_MPEG_AUDIO_ENCODING_LAYER_1,
1302 V4L2_MPEG_AUDIO_ENCODING_LAYER_3, 1,
1303 V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
1304 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
1305 return v4l2_ctrl_query_fill(qctrl,
1306 V4L2_MPEG_AUDIO_L1_BITRATE_32K,
1307 V4L2_MPEG_AUDIO_L1_BITRATE_448K, 1,
1308 V4L2_MPEG_AUDIO_L1_BITRATE_256K);
1309 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
1310 return v4l2_ctrl_query_fill(qctrl,
1311 V4L2_MPEG_AUDIO_L2_BITRATE_32K,
1312 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
1313 V4L2_MPEG_AUDIO_L2_BITRATE_224K);
1314 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
1315 return v4l2_ctrl_query_fill(qctrl,
1316 V4L2_MPEG_AUDIO_L3_BITRATE_32K,
1317 V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1,
1318 V4L2_MPEG_AUDIO_L3_BITRATE_192K);
1319 case V4L2_CID_MPEG_AUDIO_MODE:
1320 return v4l2_ctrl_query_fill(qctrl,
1321 V4L2_MPEG_AUDIO_MODE_STEREO,
1322 V4L2_MPEG_AUDIO_MODE_MONO, 1,
1323 V4L2_MPEG_AUDIO_MODE_STEREO);
1324 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
1325 return v4l2_ctrl_query_fill(qctrl,
1326 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4,
1327 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 1,
1328 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4);
1329 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
1330 return v4l2_ctrl_query_fill(qctrl,
1331 V4L2_MPEG_AUDIO_EMPHASIS_NONE,
1332 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 1,
1333 V4L2_MPEG_AUDIO_EMPHASIS_NONE);
1334 case V4L2_CID_MPEG_AUDIO_CRC:
1335 return v4l2_ctrl_query_fill(qctrl,
1336 V4L2_MPEG_AUDIO_CRC_NONE,
1337 V4L2_MPEG_AUDIO_CRC_CRC16, 1,
1338 V4L2_MPEG_AUDIO_CRC_NONE);
1339 case V4L2_CID_MPEG_VIDEO_ENCODING:
1340 return v4l2_ctrl_query_fill(qctrl,
1341 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
1342 V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 1,
1343 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
1344 case V4L2_CID_MPEG_VIDEO_ASPECT:
1345 return v4l2_ctrl_query_fill(qctrl,
1346 V4L2_MPEG_VIDEO_ASPECT_1x1,
1347 V4L2_MPEG_VIDEO_ASPECT_221x100, 1,
1348 V4L2_MPEG_VIDEO_ASPECT_4x3);
1349 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
1350 return v4l2_ctrl_query_fill(qctrl, 0, 33, 1, 2);
1351 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1352 return v4l2_ctrl_query_fill(qctrl, 1, 34, 1, 12);
1353 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
1354 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1);
1355 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
1356 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
1357 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1358 return v4l2_ctrl_query_fill(qctrl,
1359 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
1360 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
1361 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
1362 case V4L2_CID_MPEG_VIDEO_BITRATE:
1363 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
1364 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
1365 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
1366 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
1367 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
1368 case V4L2_CID_MPEG_STREAM_TYPE:
1369 return v4l2_ctrl_query_fill(qctrl,
1370 V4L2_MPEG_STREAM_TYPE_MPEG2_PS,
1371 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, 1,
1372 V4L2_MPEG_STREAM_TYPE_MPEG2_PS);
1373 case V4L2_CID_MPEG_STREAM_PID_PMT:
1374 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16);
1375 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
1376 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260);
1377 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
1378 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256);
1379 case V4L2_CID_MPEG_STREAM_PID_PCR:
1380 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259);
1381 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO:
1382 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
1383 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO:
1384 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
1385 case V4L2_CID_MPEG_STREAM_VBI_FMT:
1386 return v4l2_ctrl_query_fill(qctrl,
1387 V4L2_MPEG_STREAM_VBI_FMT_NONE,
1388 V4L2_MPEG_STREAM_VBI_FMT_IVTV, 1,
1389 V4L2_MPEG_STREAM_VBI_FMT_NONE);
1395 /* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
1396 the menu. The qctrl pointer may be NULL, in which case it is ignored. */
1397 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
1398 const char **menu_items)
1402 if (menu_items == NULL ||
1403 (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum)))
1405 for (i = 0; i < qmenu->index && menu_items[i]; i++) ;
1406 if (menu_items[i] == NULL || menu_items[i][0] == '\0')
1408 snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]);
1409 qmenu->reserved = 0;
1413 /* ctrl_classes points to an array of u32 pointers, the last element is
1414 a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
1415 Each array must be sorted low to high and belong to the same control
1416 class. The array of u32 pointer must also be sorted, from low class IDs
1419 This function returns the first ID that follows after the given ID.
1420 When no more controls are available 0 is returned. */
1421 u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
1426 /* if no query is desired, then just return the control ID */
1427 if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0)
1429 if (ctrl_classes == NULL)
1431 id &= V4L2_CTRL_ID_MASK;
1432 ctrl_class = V4L2_CTRL_ID2CLASS(id);
1433 id++; /* select next control */
1434 /* find first class that matches (or is greater than) the class of
1436 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) < ctrl_class)
1438 /* no more classes */
1439 if (*ctrl_classes == NULL)
1441 pctrl = *ctrl_classes;
1442 /* find first ctrl within the class that is >= ID */
1443 while (*pctrl && *pctrl < id) pctrl++;
1446 /* we are at the end of the controls of the current class. */
1447 /* continue with next class if available */
1449 if (*ctrl_classes == NULL)
1451 return **ctrl_classes;
1454 /* ----------------------------------------------------------------- */
1456 EXPORT_SYMBOL(v4l2_video_std_construct);
1458 EXPORT_SYMBOL(v4l2_prio_init);
1459 EXPORT_SYMBOL(v4l2_prio_change);
1460 EXPORT_SYMBOL(v4l2_prio_open);
1461 EXPORT_SYMBOL(v4l2_prio_close);
1462 EXPORT_SYMBOL(v4l2_prio_max);
1463 EXPORT_SYMBOL(v4l2_prio_check);
1465 EXPORT_SYMBOL(v4l2_field_names);
1466 EXPORT_SYMBOL(v4l2_type_names);
1467 EXPORT_SYMBOL(v4l_printk_ioctl);
1468 EXPORT_SYMBOL(v4l_printk_ioctl_arg);
1470 EXPORT_SYMBOL(v4l2_ctrl_next);
1471 EXPORT_SYMBOL(v4l2_ctrl_check);
1472 EXPORT_SYMBOL(v4l2_ctrl_get_menu);
1473 EXPORT_SYMBOL(v4l2_ctrl_query_menu);
1474 EXPORT_SYMBOL(v4l2_ctrl_query_fill);
1475 EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);