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",
194 static char *v4l2_memory_names[] = {
195 [V4L2_MEMORY_MMAP] = "mmap",
196 [V4L2_MEMORY_USERPTR] = "userptr",
197 [V4L2_MEMORY_OVERLAY] = "overlay",
200 #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
202 /* ------------------------------------------------------------------ */
203 /* debug help functions */
205 #ifdef CONFIG_VIDEO_V4L1_COMPAT
206 static const char *v4l1_ioctls[] = {
207 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
208 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
209 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
210 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
211 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
212 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
213 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
214 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
215 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
216 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
217 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
218 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
219 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
220 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
221 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
222 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
223 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
224 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
225 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
226 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
227 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
228 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
229 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
230 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
231 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
232 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
233 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
234 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
235 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
237 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
240 static const char *v4l2_ioctls[] = {
241 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
242 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
243 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
244 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
245 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
246 [_IOC_NR(VIDIOC_G_MPEGCOMP)] = "VIDIOC_G_MPEGCOMP",
247 [_IOC_NR(VIDIOC_S_MPEGCOMP)] = "VIDIOC_S_MPEGCOMP",
248 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
249 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
250 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
251 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
252 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
253 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
254 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
255 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
256 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
257 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
258 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
259 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
260 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
261 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
262 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
263 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
264 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
265 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
266 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
267 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
268 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
269 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
270 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
271 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
272 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
273 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
274 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
275 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
276 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
277 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
278 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
279 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
280 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
281 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
282 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
283 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
284 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
285 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
286 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
287 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
288 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
289 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
290 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
291 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
292 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
294 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
296 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
297 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
298 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
299 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS"
301 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
303 static const char *v4l2_int_ioctls[] = {
304 #ifdef CONFIG_VIDEO_V4L1_COMPAT
305 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
306 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
307 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
308 [_IOC_NR(DECODER_SET_INPUT)] = "DECODER_SET_INPUT",
309 [_IOC_NR(DECODER_SET_OUTPUT)] = "DECODER_SET_OUTPUT",
310 [_IOC_NR(DECODER_ENABLE_OUTPUT)] = "DECODER_ENABLE_OUTPUT",
311 [_IOC_NR(DECODER_SET_PICTURE)] = "DECODER_SET_PICTURE",
312 [_IOC_NR(DECODER_SET_GPIO)] = "DECODER_SET_GPIO",
313 [_IOC_NR(DECODER_INIT)] = "DECODER_INIT",
314 [_IOC_NR(DECODER_SET_VBI_BYPASS)] = "DECODER_SET_VBI_BYPASS",
315 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
317 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
319 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
320 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
321 [_IOC_NR(TDA9887_SET_CONFIG)] = "TDA9887_SET_CONFIG",
323 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
324 [_IOC_NR(VIDIOC_INT_S_REGISTER)] = "VIDIOC_INT_S_REGISTER",
325 [_IOC_NR(VIDIOC_INT_G_REGISTER)] = "VIDIOC_INT_G_REGISTER",
326 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
327 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
328 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
329 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
330 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
331 [_IOC_NR(VIDIOC_INT_G_CHIP_IDENT)] = "VIDIOC_INT_G_CHIP_IDENT",
332 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
333 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
334 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
335 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
336 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
337 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
338 [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ"
340 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
342 static void v4l_print_pix_fmt (char *s, struct v4l2_pix_format *fmt)
344 printk ("%s: width=%d, height=%d, format=%d, field=%s, "
345 "bytesperline=%d sizeimage=%d, colorspace=%d\n", s,
346 fmt->width,fmt->height,fmt->pixelformat,
347 prt_names(fmt->field,v4l2_field_names),
348 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
351 /* Common ioctl debug function. This function can be used by
352 external ioctl messages as well as internal V4L ioctl */
353 void v4l_printk_ioctl(unsigned int cmd)
357 switch (_IOC_DIR(cmd)) {
358 case _IOC_NONE: dir = "--"; break;
359 case _IOC_READ: dir = "r-"; break;
360 case _IOC_WRITE: dir = "-w"; break;
361 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
362 default: dir = "*ERR*"; break;
364 switch (_IOC_TYPE(cmd)) {
366 printk("v4l2_int ioctl %s, dir=%s (0x%08x)\n",
367 (_IOC_NR(cmd) < V4L2_INT_IOCTLS) ?
368 v4l2_int_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
370 #ifdef CONFIG_VIDEO_V4L1_COMPAT
372 printk("v4l1 ioctl %s, dir=%s (0x%08x)\n",
373 (_IOC_NR(cmd) < V4L1_IOCTLS) ?
374 v4l1_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
378 printk("v4l2 ioctl %s, dir=%s (0x%08x)\n",
379 (_IOC_NR(cmd) < V4L2_IOCTLS) ?
380 v4l2_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
384 printk("unknown ioctl '%c', dir=%s, #%d (0x%08x)\n",
385 _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
389 /* Common ioctl debug function. This function can be used by
390 external ioctl messages as well as internal V4L ioctl and its
392 void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
396 v4l_printk_ioctl(cmd);
398 case VIDIOC_INT_G_CHIP_IDENT:
400 enum v4l2_chip_ident *p=arg;
401 printk ("%s: chip ident=%d\n", s, *p);
404 case VIDIOC_G_PRIORITY:
405 case VIDIOC_S_PRIORITY:
407 enum v4l2_priority *p=arg;
408 printk ("%s: priority=%d\n", s, *p);
411 case VIDIOC_INT_S_TUNER_MODE:
413 enum v4l2_tuner_type *p=arg;
414 printk ("%s: tuner type=%d\n", s, *p);
417 #ifdef CONFIG_VIDEO_V4L1_COMPAT
418 case DECODER_SET_VBI_BYPASS:
419 case DECODER_ENABLE_OUTPUT:
420 case DECODER_GET_STATUS:
421 case DECODER_SET_OUTPUT:
422 case DECODER_SET_INPUT:
423 case DECODER_SET_GPIO:
424 case DECODER_SET_NORM:
427 case VIDIOCSWRITEMODE:
429 case TUNER_SET_TYPE_ADDR:
430 case TUNER_SET_STANDBY:
431 case TDA9887_SET_CONFIG:
433 case VIDIOC_OVERLAY_OLD:
435 case VIDIOC_STREAMOFF:
436 case VIDIOC_G_OUTPUT:
437 case VIDIOC_S_OUTPUT:
438 case VIDIOC_STREAMON:
444 printk ("%s: value=%d\n", s, *p);
449 case VIDIOC_ENUMAUDIO:
451 case VIDIOC_G_AUDIO_OLD:
454 struct v4l2_audio *p=arg;
456 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n",
457 s,p->index, p->name,p->capability, p->mode);
460 case VIDIOC_G_AUDOUT:
461 case VIDIOC_S_AUDOUT:
462 case VIDIOC_ENUMAUDOUT:
464 case VIDIOC_G_AUDOUT_OLD:
467 struct v4l2_audioout *p=arg;
468 printk ("%s: index=%d, name=%s, capability=%d, mode=%d\n", s,
469 p->index, p->name, p->capability,p->mode);
474 case VIDIOC_QUERYBUF:
476 struct v4l2_buffer *p=arg;
477 struct v4l2_timecode *tc=&p->timecode;
478 printk ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, "
479 "bytesused=%d, flags=0x%08x, "
480 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n",
482 (p->timestamp.tv_sec/3600),
483 (int)(p->timestamp.tv_sec/60)%60,
484 (int)(p->timestamp.tv_sec%60),
485 p->timestamp.tv_usec,
487 prt_names(p->type,v4l2_type_names),
488 p->bytesused,p->flags,
489 p->field,p->sequence,
490 prt_names(p->memory,v4l2_memory_names),
492 printk ("%s: timecode= %02d:%02d:%02d type=%d, "
493 "flags=0x%08x, frames=%d, userbits=0x%08x\n",
494 s,tc->hours,tc->minutes,tc->seconds,
495 tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
498 case VIDIOC_QUERYCAP:
500 struct v4l2_capability *p=arg;
501 printk ("%s: driver=%s, card=%s, bus=%s, version=0x%08x, "
502 "capabilities=0x%08x\n", s,
503 p->driver,p->card,p->bus_info,
511 case VIDIOC_S_CTRL_OLD:
514 struct v4l2_control *p=arg;
515 printk ("%s: id=%d, value=%d\n", s, p->id, p->value);
518 case VIDIOC_G_EXT_CTRLS:
519 case VIDIOC_S_EXT_CTRLS:
520 case VIDIOC_TRY_EXT_CTRLS:
522 struct v4l2_ext_controls *p = arg;
525 printk("%s: ctrl_class=%d, count=%d\n", s, p->ctrl_class, p->count);
526 for (i = 0; i < p->count; i++) {
527 struct v4l2_ext_control *c = &p->controls[i];
528 if (cmd == VIDIOC_G_EXT_CTRLS)
529 printk("%s: id=%d\n", s, c->id);
531 printk("%s: id=%d, value=%d\n", s, c->id, c->value);
538 struct v4l2_crop *p=arg;
539 /*FIXME: Should also show rect structs */
540 printk ("%s: type=%d\n", s, p->type);
545 case VIDIOC_CROPCAP_OLD:
548 struct v4l2_cropcap *p=arg;
549 /*FIXME: Should also show rect structs */
550 printk ("%s: type=%d\n", s, p->type);
553 case VIDIOC_INT_DECODE_VBI_LINE:
555 struct v4l2_decode_vbi_line *p=arg;
556 printk ("%s: is_second_field=%d, ptr=0x%08lx, line=%d, "
558 p->is_second_field,(unsigned long)p->p,p->line,p->type);
561 case VIDIOC_ENUM_FMT:
563 struct v4l2_fmtdesc *p=arg;
564 printk ("%s: index=%d, type=%d, flags=%d, description=%s,"
565 " pixelformat=%d\n", s,
566 p->index, p->type, p->flags,p->description,
575 struct v4l2_format *p=arg;
576 printk ("%s: type=%s\n", s,
577 prt_names(p->type,v4l2_type_names));
579 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
580 v4l_print_pix_fmt (s, &p->fmt.pix);
589 struct v4l2_framebuffer *p=arg;
590 printk ("%s: capability=%d, flags=%d, base=0x%08lx\n", s,
591 p->capability,p->flags, (unsigned long)p->base);
592 v4l_print_pix_fmt (s, &p->fmt);
595 case VIDIOC_G_FREQUENCY:
596 case VIDIOC_S_FREQUENCY:
598 struct v4l2_frequency *p=arg;
599 printk ("%s: tuner=%d, type=%d, frequency=%d\n", s,
600 p->tuner,p->type,p->frequency);
603 case VIDIOC_ENUMINPUT:
605 struct v4l2_input *p=arg;
606 printk ("%s: index=%d, name=%s, type=%d, audioset=%d, "
607 "tuner=%d, std=%Ld, status=%d\n", s,
608 p->index,p->name,p->type,p->audioset,
610 (unsigned long long)p->std,
614 case VIDIOC_G_JPEGCOMP:
615 case VIDIOC_S_JPEGCOMP:
617 struct v4l2_jpegcompression *p=arg;
618 printk ("%s: quality=%d, APPn=%d, APP_len=%d, COM_len=%d,"
619 " jpeg_markers=%d\n", s,
620 p->quality,p->APPn,p->APP_len,
621 p->COM_len,p->jpeg_markers);
624 case VIDIOC_G_MODULATOR:
625 case VIDIOC_S_MODULATOR:
627 struct v4l2_modulator *p=arg;
628 printk ("%s: index=%d, name=%s, capability=%d, rangelow=%d,"
629 " rangehigh=%d, txsubchans=%d\n", s,
630 p->index, p->name,p->capability,p->rangelow,
631 p->rangehigh,p->txsubchans);
634 case VIDIOC_G_MPEGCOMP:
635 case VIDIOC_S_MPEGCOMP:
637 struct v4l2_mpeg_compression *p=arg;
638 /*FIXME: Several fields not shown */
639 printk ("%s: ts_pid_pmt=%d, ts_pid_audio=%d, ts_pid_video=%d, "
640 "ts_pid_pcr=%d, ps_size=%d, au_sample_rate=%d, "
641 "au_pesid=%c, vi_frame_rate=%d, vi_frames_per_gop=%d, "
642 "vi_bframes_count=%d, vi_pesid=%c\n", s,
643 p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
644 p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
645 p->au_pesid, p->vi_frame_rate,
646 p->vi_frames_per_gop, p->vi_bframes_count,
650 case VIDIOC_ENUMOUTPUT:
652 struct v4l2_output *p=arg;
653 printk ("%s: index=%d, name=%s,type=%d, audioset=%d, "
654 "modulator=%d, std=%Ld\n",
655 s,p->index,p->name,p->type,p->audioset,
657 (unsigned long long)p->std);
660 case VIDIOC_QUERYCTRL:
662 struct v4l2_queryctrl *p=arg;
663 printk ("%s: id=%d, type=%d, name=%s, min/max=%d/%d,"
664 " step=%d, default=%d, flags=0x%08x\n", s,
665 p->id,p->type,p->name,p->minimum,p->maximum,
666 p->step,p->default_value,p->flags);
669 case VIDIOC_QUERYMENU:
671 struct v4l2_querymenu *p=arg;
672 printk ("%s: id=%d, index=%d, name=%s\n", s,
673 p->id,p->index,p->name);
676 case VIDIOC_INT_G_REGISTER:
677 case VIDIOC_INT_S_REGISTER:
679 struct v4l2_register *p=arg;
680 printk ("%s: i2c_id=%d, reg=%lu, val=%d\n", s,
681 p->i2c_id,p->reg,p->val);
687 struct v4l2_requestbuffers *p=arg;
688 printk ("%s: count=%d, type=%s, memory=%s\n", s,
690 prt_names(p->type,v4l2_type_names),
691 prt_names(p->memory,v4l2_memory_names));
694 case VIDIOC_INT_S_AUDIO_ROUTING:
695 case VIDIOC_INT_S_VIDEO_ROUTING:
696 case VIDIOC_INT_G_AUDIO_ROUTING:
697 case VIDIOC_INT_G_VIDEO_ROUTING:
699 struct v4l2_routing *p=arg;
700 printk ("%s: input=0x%x, output=0x%x\n", s, p->input, p->output);
703 case VIDIOC_INT_S_CRYSTAL_FREQ:
705 struct v4l2_crystal_freq *p=arg;
706 printk ("%s: freq=%u, flags=0x%x\n", s, p->freq, p->flags);
709 case VIDIOC_G_SLICED_VBI_CAP:
711 struct v4l2_sliced_vbi_cap *p=arg;
712 printk ("%s: service_set=%d\n", s,
716 case VIDIOC_INT_S_VBI_DATA:
717 case VIDIOC_INT_G_VBI_DATA:
719 struct v4l2_sliced_vbi_data *p=arg;
720 printk ("%s: id=%d, field=%d, line=%d\n", s,
721 p->id, p->field, p->line);
726 struct v4l2_standard *p=arg;
727 printk ("%s: index=%d, id=%Ld, name=%s, fps=%d/%d, "
728 "framelines=%d\n", s, p->index,
729 (unsigned long long)p->id, p->name,
730 p->frameperiod.numerator,
731 p->frameperiod.denominator,
739 case VIDIOC_S_PARM_OLD:
742 struct v4l2_streamparm *p=arg;
743 printk ("%s: type=%d\n", s, p->type);
750 struct v4l2_tuner *p=arg;
751 printk ("%s: index=%d, name=%s, type=%d, capability=%d, "
752 "rangelow=%d, rangehigh=%d, signal=%d, afc=%d, "
753 "rxsubchans=%d, audmode=%d\n", s,
754 p->index, p->name, p->type,
755 p->capability, p->rangelow,p->rangehigh,
756 p->rxsubchans, p->audmode, p->signal,
760 #ifdef CONFIG_VIDEO_V4L1_COMPAT
764 struct vbi_format *p=arg;
765 printk ("%s: sampling_rate=%d, samples_per_line=%d, "
766 "sample_format=%d, start=%d/%d, count=%d/%d, flags=%d\n", s,
767 p->sampling_rate,p->samples_per_line,
768 p->sample_format,p->start[0],p->start[1],
769 p->count[0],p->count[1],p->flags);
775 struct video_audio *p=arg;
776 printk ("%s: audio=%d, volume=%d, bass=%d, treble=%d, "
777 "flags=%d, name=%s, mode=%d, balance=%d, step=%d\n",
778 s,p->audio,p->volume,p->bass, p->treble,
779 p->flags,p->name,p->mode,p->balance,p->step);
785 struct video_buffer *p=arg;
786 printk ("%s: base=%08lx, height=%d, width=%d, depth=%d, "
787 "bytesperline=%d\n", s,
788 (unsigned long) p->base, p->height, p->width,
789 p->depth,p->bytesperline);
794 struct video_capability *p=arg;
795 printk ("%s: name=%s, type=%d, channels=%d, audios=%d, "
796 "maxwidth=%d, maxheight=%d, minwidth=%d, minheight=%d\n",
797 s,p->name,p->type,p->channels,p->audios,
798 p->maxwidth,p->maxheight,p->minwidth,
806 struct video_capture *p=arg;
807 printk ("%s: x=%d, y=%d, width=%d, height=%d, decimation=%d,"
809 p->x, p->y,p->width, p->height,
810 p->decimation,p->flags);
816 struct video_channel *p=arg;
817 printk ("%s: channel=%d, name=%s, tuners=%d, flags=%d, "
818 "type=%d, norm=%d\n", s,
819 p->channel,p->name,p->tuners,
820 p->flags,p->type,p->norm);
824 case VIDIOCSMICROCODE:
826 struct video_code *p=arg;
827 printk ("%s: loadwhat=%s, datasize=%d\n", s,
828 p->loadwhat,p->datasize);
831 case DECODER_GET_CAPABILITIES:
833 struct video_decoder_capability *p=arg;
834 printk ("%s: flags=%d, inputs=%d, outputs=%d\n", s,
835 p->flags,p->inputs,p->outputs);
840 struct video_decoder_init *p=arg;
841 printk ("%s: len=%c\n", s, p->len);
844 case VIDIOCGPLAYINFO:
846 struct video_info *p=arg;
847 printk ("%s: frame_count=%d, h_size=%d, v_size=%d, "
848 "smpte_timecode=%d, picture_type=%d, "
849 "temporal_reference=%d, user_data=%s\n", s,
850 p->frame_count, p->h_size,
851 p->v_size, p->smpte_timecode,
852 p->picture_type, p->temporal_reference,
858 struct video_key *p=arg;
859 printk ("%s: key=%s, flags=%d\n", s,
865 struct video_mbuf *p=arg;
866 printk ("%s: size=%d, frames=%d, offsets=0x%08lx\n", s,
869 (unsigned long)p->offsets);
874 struct video_mmap *p=arg;
875 printk ("%s: frame=%d, height=%d, width=%d, format=%d\n", s,
883 case DECODER_SET_PICTURE:
885 struct video_picture *p=arg;
887 printk ("%s: brightness=%d, hue=%d, colour=%d, contrast=%d,"
888 " whiteness=%d, depth=%d, palette=%d\n", s,
889 p->brightness, p->hue, p->colour,
890 p->contrast, p->whiteness, p->depth,
894 case VIDIOCSPLAYMODE:
896 struct video_play_mode *p=arg;
897 printk ("%s: mode=%d, p1=%d, p2=%d\n", s,
898 p->mode,p->p1,p->p2);
904 struct video_tuner *p=arg;
905 printk ("%s: tuner=%d, name=%s, rangelow=%ld, rangehigh=%ld, "
906 "flags=%d, mode=%d, signal=%d\n", s,
907 p->tuner, p->name,p->rangelow, p->rangehigh,
908 p->flags,p->mode, p->signal);
913 struct video_unit *p=arg;
914 printk ("%s: video=%d, vbi=%d, radio=%d, audio=%d, "
916 p->video,p->vbi,p->radio,p->audio,p->teletext);
922 struct video_window *p=arg;
923 printk ("%s: x=%d, y=%d, width=%d, height=%d, chromakey=%d,"
924 " flags=%d, clipcount=%d\n", s,
925 p->x, p->y,p->width, p->height,
926 p->chromakey,p->flags,
933 unsigned long *p=arg;
934 printk ("%s: value=%lu\n", s, *p);
938 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
939 case VIDIOC_INT_I2S_CLOCK_FREQ:
940 case VIDIOC_INT_S_STANDBY:
941 case VIDIOC_INT_RESET:
945 printk ("%s: value=%d\n", s, *p);
950 case VIDIOC_QUERYSTD:
954 printk ("%s: value=%Lu\n", s, (unsigned long long)*p);
960 /* ----------------------------------------------------------------- */
962 /* Helper functions for control handling */
964 /* Check for correctness of the ctrl's value based on the data from
965 struct v4l2_queryctrl and the available menu items. Note that
966 menu_items may be NULL, in that case it is ignored. */
967 int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
968 const char **menu_items)
970 if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED)
972 if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED)
974 if (qctrl->type == V4L2_CTRL_TYPE_BUTTON ||
975 qctrl->type == V4L2_CTRL_TYPE_INTEGER64 ||
976 qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
978 if (ctrl->value < qctrl->minimum || ctrl->value > qctrl->maximum)
980 if (qctrl->type == V4L2_CTRL_TYPE_MENU && menu_items != NULL) {
981 if (menu_items[ctrl->value] == NULL ||
982 menu_items[ctrl->value][0] == '\0')
988 /* Returns NULL or a character pointer array containing the menu for
989 the given control ID. The pointer array ends with a NULL pointer.
990 An empty string signifies a menu entry that is invalid. This allows
991 drivers to disable certain options if it is not supported. */
992 const char **v4l2_ctrl_get_menu(u32 id)
994 static const char *mpeg_audio_sampling_freq[] = {
1000 static const char *mpeg_audio_encoding[] = {
1006 static const char *mpeg_audio_l1_bitrate[] = {
1023 static const char *mpeg_audio_l2_bitrate[] = {
1040 static const char *mpeg_audio_l3_bitrate[] = {
1057 static const char *mpeg_audio_mode[] = {
1064 static const char *mpeg_audio_mode_extension[] = {
1071 static const char *mpeg_audio_emphasis[] = {
1077 static const char *mpeg_audio_crc[] = {
1082 static const char *mpeg_video_encoding[] = {
1087 static const char *mpeg_video_aspect[] = {
1094 static const char *mpeg_video_bitrate_mode[] = {
1099 static const char *mpeg_stream_type[] = {
1100 "MPEG-2 Program Stream",
1101 "MPEG-2 Transport Stream",
1102 "MPEG-1 System Stream",
1103 "MPEG-2 DVD-compatible Stream",
1104 "MPEG-1 VCD-compatible Stream",
1105 "MPEG-2 SVCD-compatible Stream",
1108 static const char *mpeg_stream_vbi_fmt[] = {
1110 "Private packet, IVTV format",
1115 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1116 return mpeg_audio_sampling_freq;
1117 case V4L2_CID_MPEG_AUDIO_ENCODING:
1118 return mpeg_audio_encoding;
1119 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
1120 return mpeg_audio_l1_bitrate;
1121 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
1122 return mpeg_audio_l2_bitrate;
1123 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
1124 return mpeg_audio_l3_bitrate;
1125 case V4L2_CID_MPEG_AUDIO_MODE:
1126 return mpeg_audio_mode;
1127 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
1128 return mpeg_audio_mode_extension;
1129 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
1130 return mpeg_audio_emphasis;
1131 case V4L2_CID_MPEG_AUDIO_CRC:
1132 return mpeg_audio_crc;
1133 case V4L2_CID_MPEG_VIDEO_ENCODING:
1134 return mpeg_video_encoding;
1135 case V4L2_CID_MPEG_VIDEO_ASPECT:
1136 return mpeg_video_aspect;
1137 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1138 return mpeg_video_bitrate_mode;
1139 case V4L2_CID_MPEG_STREAM_TYPE:
1140 return mpeg_stream_type;
1141 case V4L2_CID_MPEG_STREAM_VBI_FMT:
1142 return mpeg_stream_vbi_fmt;
1148 /* Fill in a struct v4l2_queryctrl */
1149 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
1154 switch (qctrl->id) {
1156 case V4L2_CID_USER_CLASS: name = "User Controls"; break;
1157 case V4L2_CID_AUDIO_VOLUME: name = "Volume"; break;
1158 case V4L2_CID_AUDIO_MUTE: name = "Mute"; break;
1159 case V4L2_CID_AUDIO_BALANCE: name = "Balance"; break;
1160 case V4L2_CID_AUDIO_BASS: name = "Bass"; break;
1161 case V4L2_CID_AUDIO_TREBLE: name = "Treble"; break;
1162 case V4L2_CID_AUDIO_LOUDNESS: name = "Loudness"; break;
1163 case V4L2_CID_BRIGHTNESS: name = "Brightness"; break;
1164 case V4L2_CID_CONTRAST: name = "Contrast"; break;
1165 case V4L2_CID_SATURATION: name = "Saturation"; break;
1166 case V4L2_CID_HUE: name = "Hue"; break;
1169 case V4L2_CID_MPEG_CLASS: name = "MPEG Encoder Controls"; break;
1170 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: name = "Audio Sampling Frequency"; break;
1171 case V4L2_CID_MPEG_AUDIO_ENCODING: name = "Audio Encoding Layer"; break;
1172 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: name = "Audio Layer I Bitrate"; break;
1173 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: name = "Audio Layer II Bitrate"; break;
1174 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: name = "Audio Layer III Bitrate"; break;
1175 case V4L2_CID_MPEG_AUDIO_MODE: name = "Audio Stereo Mode"; break;
1176 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: name = "Audio Stereo Mode Extension"; break;
1177 case V4L2_CID_MPEG_AUDIO_EMPHASIS: name = "Audio Emphasis"; break;
1178 case V4L2_CID_MPEG_AUDIO_CRC: name = "Audio CRC"; break;
1179 case V4L2_CID_MPEG_VIDEO_ENCODING: name = "Video Encoding"; break;
1180 case V4L2_CID_MPEG_VIDEO_ASPECT: name = "Video Aspect"; break;
1181 case V4L2_CID_MPEG_VIDEO_B_FRAMES: name = "Video B Frames"; break;
1182 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: name = "Video GOP Size"; break;
1183 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: name = "Video GOP Closure"; break;
1184 case V4L2_CID_MPEG_VIDEO_PULLDOWN: name = "Video Pulldown"; break;
1185 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: name = "Video Bitrate Mode"; break;
1186 case V4L2_CID_MPEG_VIDEO_BITRATE: name = "Video Bitrate"; break;
1187 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: name = "Video Peak Bitrate"; break;
1188 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: name = "Video Temporal Decimation"; break;
1189 case V4L2_CID_MPEG_STREAM_TYPE: name = "Stream Type"; break;
1190 case V4L2_CID_MPEG_STREAM_PID_PMT: name = "Stream PMT Program ID"; break;
1191 case V4L2_CID_MPEG_STREAM_PID_AUDIO: name = "Stream Audio Program ID"; break;
1192 case V4L2_CID_MPEG_STREAM_PID_VIDEO: name = "Stream Video Program ID"; break;
1193 case V4L2_CID_MPEG_STREAM_PID_PCR: name = "Stream PCR Program ID"; break;
1194 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: name = "Stream PES Audio ID"; break;
1195 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: name = "Stream PES Video ID"; break;
1196 case V4L2_CID_MPEG_STREAM_VBI_FMT: name = "Stream VBI Format"; break;
1201 switch (qctrl->id) {
1202 case V4L2_CID_AUDIO_MUTE:
1203 case V4L2_CID_AUDIO_LOUDNESS:
1204 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
1205 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
1206 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
1210 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1211 case V4L2_CID_MPEG_AUDIO_ENCODING:
1212 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
1213 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
1214 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
1215 case V4L2_CID_MPEG_AUDIO_MODE:
1216 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
1217 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
1218 case V4L2_CID_MPEG_AUDIO_CRC:
1219 case V4L2_CID_MPEG_VIDEO_ENCODING:
1220 case V4L2_CID_MPEG_VIDEO_ASPECT:
1221 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1222 case V4L2_CID_MPEG_STREAM_TYPE:
1223 case V4L2_CID_MPEG_STREAM_VBI_FMT:
1224 qctrl->type = V4L2_CTRL_TYPE_MENU;
1227 case V4L2_CID_USER_CLASS:
1228 case V4L2_CID_MPEG_CLASS:
1229 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
1230 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1231 min = max = step = def = 0;
1234 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
1237 switch (qctrl->id) {
1238 case V4L2_CID_MPEG_AUDIO_ENCODING:
1239 case V4L2_CID_MPEG_AUDIO_MODE:
1240 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1241 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
1242 case V4L2_CID_MPEG_STREAM_TYPE:
1243 qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
1245 case V4L2_CID_AUDIO_VOLUME:
1246 case V4L2_CID_AUDIO_BALANCE:
1247 case V4L2_CID_AUDIO_BASS:
1248 case V4L2_CID_AUDIO_TREBLE:
1249 case V4L2_CID_BRIGHTNESS:
1250 case V4L2_CID_CONTRAST:
1251 case V4L2_CID_SATURATION:
1253 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
1256 qctrl->minimum = min;
1257 qctrl->maximum = max;
1259 qctrl->default_value = def;
1260 qctrl->reserved[0] = qctrl->reserved[1] = 0;
1261 snprintf(qctrl->name, sizeof(qctrl->name), name);
1265 /* Fill in a struct v4l2_queryctrl with standard values based on
1267 int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
1269 switch (qctrl->id) {
1271 case V4L2_CID_USER_CLASS:
1272 case V4L2_CID_MPEG_CLASS:
1273 return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0);
1274 case V4L2_CID_AUDIO_VOLUME:
1275 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 58880);
1276 case V4L2_CID_AUDIO_MUTE:
1277 case V4L2_CID_AUDIO_LOUDNESS:
1278 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
1279 case V4L2_CID_AUDIO_BALANCE:
1280 case V4L2_CID_AUDIO_BASS:
1281 case V4L2_CID_AUDIO_TREBLE:
1282 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 32768);
1283 case V4L2_CID_BRIGHTNESS:
1284 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
1285 case V4L2_CID_CONTRAST:
1286 case V4L2_CID_SATURATION:
1287 return v4l2_ctrl_query_fill(qctrl, 0, 127, 1, 64);
1289 return v4l2_ctrl_query_fill(qctrl, -128, 127, 1, 0);
1292 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1293 return v4l2_ctrl_query_fill(qctrl,
1294 V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100,
1295 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 1,
1296 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
1297 case V4L2_CID_MPEG_AUDIO_ENCODING:
1298 return v4l2_ctrl_query_fill(qctrl,
1299 V4L2_MPEG_AUDIO_ENCODING_LAYER_1,
1300 V4L2_MPEG_AUDIO_ENCODING_LAYER_3, 1,
1301 V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
1302 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
1303 return v4l2_ctrl_query_fill(qctrl,
1304 V4L2_MPEG_AUDIO_L1_BITRATE_32K,
1305 V4L2_MPEG_AUDIO_L1_BITRATE_448K, 1,
1306 V4L2_MPEG_AUDIO_L1_BITRATE_256K);
1307 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
1308 return v4l2_ctrl_query_fill(qctrl,
1309 V4L2_MPEG_AUDIO_L2_BITRATE_32K,
1310 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
1311 V4L2_MPEG_AUDIO_L2_BITRATE_224K);
1312 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
1313 return v4l2_ctrl_query_fill(qctrl,
1314 V4L2_MPEG_AUDIO_L3_BITRATE_32K,
1315 V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1,
1316 V4L2_MPEG_AUDIO_L3_BITRATE_192K);
1317 case V4L2_CID_MPEG_AUDIO_MODE:
1318 return v4l2_ctrl_query_fill(qctrl,
1319 V4L2_MPEG_AUDIO_MODE_STEREO,
1320 V4L2_MPEG_AUDIO_MODE_MONO, 1,
1321 V4L2_MPEG_AUDIO_MODE_STEREO);
1322 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
1323 return v4l2_ctrl_query_fill(qctrl,
1324 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4,
1325 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 1,
1326 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4);
1327 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
1328 return v4l2_ctrl_query_fill(qctrl,
1329 V4L2_MPEG_AUDIO_EMPHASIS_NONE,
1330 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 1,
1331 V4L2_MPEG_AUDIO_EMPHASIS_NONE);
1332 case V4L2_CID_MPEG_AUDIO_CRC:
1333 return v4l2_ctrl_query_fill(qctrl,
1334 V4L2_MPEG_AUDIO_CRC_NONE,
1335 V4L2_MPEG_AUDIO_CRC_CRC16, 1,
1336 V4L2_MPEG_AUDIO_CRC_NONE);
1337 case V4L2_CID_MPEG_VIDEO_ENCODING:
1338 return v4l2_ctrl_query_fill(qctrl,
1339 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
1340 V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 1,
1341 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
1342 case V4L2_CID_MPEG_VIDEO_ASPECT:
1343 return v4l2_ctrl_query_fill(qctrl,
1344 V4L2_MPEG_VIDEO_ASPECT_1x1,
1345 V4L2_MPEG_VIDEO_ASPECT_221x100, 1,
1346 V4L2_MPEG_VIDEO_ASPECT_4x3);
1347 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
1348 return v4l2_ctrl_query_fill(qctrl, 0, 33, 1, 2);
1349 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1350 return v4l2_ctrl_query_fill(qctrl, 1, 34, 1, 12);
1351 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
1352 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1);
1353 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
1354 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
1355 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1356 return v4l2_ctrl_query_fill(qctrl,
1357 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
1358 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
1359 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
1360 case V4L2_CID_MPEG_VIDEO_BITRATE:
1361 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
1362 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
1363 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
1364 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
1365 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
1366 case V4L2_CID_MPEG_STREAM_TYPE:
1367 return v4l2_ctrl_query_fill(qctrl,
1368 V4L2_MPEG_STREAM_TYPE_MPEG2_PS,
1369 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, 1,
1370 V4L2_MPEG_STREAM_TYPE_MPEG2_PS);
1371 case V4L2_CID_MPEG_STREAM_PID_PMT:
1372 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16);
1373 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
1374 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260);
1375 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
1376 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256);
1377 case V4L2_CID_MPEG_STREAM_PID_PCR:
1378 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259);
1379 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO:
1380 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
1381 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO:
1382 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
1383 case V4L2_CID_MPEG_STREAM_VBI_FMT:
1384 return v4l2_ctrl_query_fill(qctrl,
1385 V4L2_MPEG_STREAM_VBI_FMT_NONE,
1386 V4L2_MPEG_STREAM_VBI_FMT_IVTV, 1,
1387 V4L2_MPEG_STREAM_VBI_FMT_NONE);
1393 /* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
1394 the menu. The qctrl pointer may be NULL, in which case it is ignored. */
1395 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
1396 const char **menu_items)
1400 if (menu_items == NULL ||
1401 (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum)))
1403 for (i = 0; i < qmenu->index && menu_items[i]; i++) ;
1404 if (menu_items[i] == NULL || menu_items[i][0] == '\0')
1406 snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]);
1407 qmenu->reserved = 0;
1411 /* ctrl_classes points to an array of u32 pointers, the last element is
1412 a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
1413 Each array must be sorted low to high and belong to the same control
1414 class. The array of u32 pointer must also be sorted, from low class IDs
1417 This function returns the first ID that follows after the given ID.
1418 When no more controls are available 0 is returned. */
1419 u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
1424 /* if no query is desired, then just return the control ID */
1425 if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0)
1427 if (ctrl_classes == NULL)
1429 id &= V4L2_CTRL_ID_MASK;
1430 ctrl_class = V4L2_CTRL_ID2CLASS(id);
1431 id++; /* select next control */
1432 /* find first class that matches (or is greater than) the class of
1434 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) < ctrl_class)
1436 /* no more classes */
1437 if (*ctrl_classes == NULL)
1439 pctrl = *ctrl_classes;
1440 /* find first ctrl within the class that is >= ID */
1441 while (*pctrl && *pctrl < id) pctrl++;
1444 /* we are at the end of the controls of the current class. */
1445 /* continue with next class if available */
1447 if (*ctrl_classes == NULL)
1449 return **ctrl_classes;
1452 /* ----------------------------------------------------------------- */
1454 EXPORT_SYMBOL(v4l2_video_std_construct);
1456 EXPORT_SYMBOL(v4l2_prio_init);
1457 EXPORT_SYMBOL(v4l2_prio_change);
1458 EXPORT_SYMBOL(v4l2_prio_open);
1459 EXPORT_SYMBOL(v4l2_prio_close);
1460 EXPORT_SYMBOL(v4l2_prio_max);
1461 EXPORT_SYMBOL(v4l2_prio_check);
1463 EXPORT_SYMBOL(v4l2_field_names);
1464 EXPORT_SYMBOL(v4l2_type_names);
1465 EXPORT_SYMBOL(v4l_printk_ioctl);
1466 EXPORT_SYMBOL(v4l_printk_ioctl_arg);
1468 EXPORT_SYMBOL(v4l2_ctrl_next);
1469 EXPORT_SYMBOL(v4l2_ctrl_check);
1470 EXPORT_SYMBOL(v4l2_ctrl_get_menu);
1471 EXPORT_SYMBOL(v4l2_ctrl_query_menu);
1472 EXPORT_SYMBOL(v4l2_ctrl_query_fill);
1473 EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);