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 <bill@thedirks.org>
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/smp_lock.h>
52 #include <linux/string.h>
53 #include <linux/errno.h>
54 #include <linux/i2c.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 char *v4l2_norm_to_name(v4l2_std_id id)
95 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
96 64 bit comparations. So, on that architecture, with some gcc variants,
97 compilation fails. Currently, the max value is 30bit wide.
104 case V4L2_STD_PAL_BG:
105 name="PAL-BG"; break;
106 case V4L2_STD_PAL_DK:
107 name="PAL-DK"; break;
110 case V4L2_STD_PAL_B1:
111 name="PAL-B1"; break;
120 case V4L2_STD_PAL_D1:
121 name="PAL-D1"; break;
128 case V4L2_STD_PAL_Nc:
129 name="PAL-Nc"; break;
130 case V4L2_STD_PAL_60:
131 name="PAL-60"; break;
134 case V4L2_STD_NTSC_M:
135 name="NTSC-M"; break;
136 case V4L2_STD_NTSC_M_JP:
137 name="NTSC-M-JP"; break;
138 case V4L2_STD_NTSC_443:
139 name="NTSC-443"; break;
140 case V4L2_STD_NTSC_M_KR:
141 name="NTSC-M-KR"; break;
144 case V4L2_STD_SECAM_DK:
145 name="SECAM-DK"; break;
146 case V4L2_STD_SECAM_B:
147 name="SECAM-B"; break;
148 case V4L2_STD_SECAM_D:
149 name="SECAM-D"; break;
150 case V4L2_STD_SECAM_G:
151 name="SECAM-G"; break;
152 case V4L2_STD_SECAM_H:
153 name="SECAM-H"; break;
154 case V4L2_STD_SECAM_K:
155 name="SECAM-K"; break;
156 case V4L2_STD_SECAM_K1:
157 name="SECAM-K1"; break;
158 case V4L2_STD_SECAM_L:
159 name="SECAM-L"; break;
160 case V4L2_STD_SECAM_LC:
161 name="SECAM-LC"; break;
163 name="Unknown"; break;
169 /* Fill in the fields of a v4l2_standard structure according to the
170 'id' and 'transmission' parameters. Returns negative on error. */
171 int v4l2_video_std_construct(struct v4l2_standard *vs,
174 u32 index = vs->index;
176 memset(vs, 0, sizeof(struct v4l2_standard));
179 if (id & V4L2_STD_525_60) {
180 vs->frameperiod.numerator = 1001;
181 vs->frameperiod.denominator = 30000;
182 vs->framelines = 525;
184 vs->frameperiod.numerator = 1;
185 vs->frameperiod.denominator = 25;
186 vs->framelines = 625;
188 strlcpy(vs->name,name,sizeof(vs->name));
192 /* ----------------------------------------------------------------- */
193 /* priority handling */
195 #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND || \
196 val == V4L2_PRIORITY_INTERACTIVE || \
197 val == V4L2_PRIORITY_RECORD)
199 int v4l2_prio_init(struct v4l2_prio_state *global)
201 memset(global,0,sizeof(*global));
205 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
206 enum v4l2_priority new)
208 if (!V4L2_PRIO_VALID(new))
213 atomic_inc(&global->prios[new]);
214 if (V4L2_PRIO_VALID(*local))
215 atomic_dec(&global->prios[*local]);
220 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
222 return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
225 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
227 if (V4L2_PRIO_VALID(*local))
228 atomic_dec(&global->prios[*local]);
232 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
234 if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
235 return V4L2_PRIORITY_RECORD;
236 if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
237 return V4L2_PRIORITY_INTERACTIVE;
238 if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
239 return V4L2_PRIORITY_BACKGROUND;
240 return V4L2_PRIORITY_UNSET;
243 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
245 if (*local < v4l2_prio_max(global))
251 /* ----------------------------------------------------------------- */
252 /* some arrays for pretty-printing debug messages of enum types */
254 char *v4l2_field_names[] = {
255 [V4L2_FIELD_ANY] = "any",
256 [V4L2_FIELD_NONE] = "none",
257 [V4L2_FIELD_TOP] = "top",
258 [V4L2_FIELD_BOTTOM] = "bottom",
259 [V4L2_FIELD_INTERLACED] = "interlaced",
260 [V4L2_FIELD_SEQ_TB] = "seq-tb",
261 [V4L2_FIELD_SEQ_BT] = "seq-bt",
262 [V4L2_FIELD_ALTERNATE] = "alternate",
265 char *v4l2_type_names[] = {
266 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
267 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
268 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
269 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
270 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
271 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
272 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "slicec-vbi-out",
276 #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
278 /* ------------------------------------------------------------------ */
279 /* debug help functions */
281 #ifdef CONFIG_VIDEO_V4L1_COMPAT
282 static const char *v4l1_ioctls[] = {
283 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
284 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
285 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
286 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
287 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
288 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
289 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
290 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
291 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
292 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
293 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
294 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
295 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
296 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
297 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
298 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
299 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
300 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
301 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
302 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
303 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
304 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
305 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
306 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
307 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
308 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
309 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
310 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
311 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
313 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
316 static const char *v4l2_ioctls[] = {
317 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
318 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
319 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
320 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
321 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
322 [_IOC_NR(VIDIOC_G_MPEGCOMP)] = "VIDIOC_G_MPEGCOMP",
323 [_IOC_NR(VIDIOC_S_MPEGCOMP)] = "VIDIOC_S_MPEGCOMP",
324 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
325 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
326 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
327 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
328 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
329 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
330 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
331 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
332 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
333 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
334 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
335 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
336 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
337 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
338 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
339 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
340 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
341 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
342 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
343 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
344 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
345 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
346 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
347 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
348 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
349 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
350 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
351 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
352 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
353 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
354 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
355 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
356 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
357 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
358 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
359 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
360 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
361 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
362 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
363 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
364 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
365 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
366 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
367 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
368 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
369 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
370 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
371 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
372 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
373 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
375 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
376 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
377 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
378 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
379 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
381 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
382 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
385 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
387 static const char *v4l2_int_ioctls[] = {
388 #ifdef CONFIG_VIDEO_V4L1_COMPAT
389 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
390 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
391 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
392 [_IOC_NR(DECODER_SET_INPUT)] = "DECODER_SET_INPUT",
393 [_IOC_NR(DECODER_SET_OUTPUT)] = "DECODER_SET_OUTPUT",
394 [_IOC_NR(DECODER_ENABLE_OUTPUT)] = "DECODER_ENABLE_OUTPUT",
395 [_IOC_NR(DECODER_SET_PICTURE)] = "DECODER_SET_PICTURE",
396 [_IOC_NR(DECODER_SET_GPIO)] = "DECODER_SET_GPIO",
397 [_IOC_NR(DECODER_INIT)] = "DECODER_INIT",
398 [_IOC_NR(DECODER_SET_VBI_BYPASS)] = "DECODER_SET_VBI_BYPASS",
399 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
401 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
403 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
404 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
405 [_IOC_NR(TDA9887_SET_CONFIG)] = "TDA9887_SET_CONFIG",
407 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
408 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
409 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
410 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
411 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
412 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
413 [_IOC_NR(VIDIOC_INT_G_CHIP_IDENT)] = "VIDIOC_INT_G_CHIP_IDENT",
414 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
415 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
416 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
417 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
418 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
419 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
420 [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ"
422 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
425 /* Common ioctl debug function. This function can be used by
426 external ioctl messages as well as internal V4L ioctl */
427 void v4l_printk_ioctl(unsigned int cmd)
431 switch (_IOC_DIR(cmd)) {
432 case _IOC_NONE: dir = "--"; break;
433 case _IOC_READ: dir = "r-"; break;
434 case _IOC_WRITE: dir = "-w"; break;
435 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
436 default: dir = "*ERR*"; break;
438 switch (_IOC_TYPE(cmd)) {
440 printk("v4l2_int ioctl %s, dir=%s (0x%08x)\n",
441 (_IOC_NR(cmd) < V4L2_INT_IOCTLS) ?
442 v4l2_int_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
444 #ifdef CONFIG_VIDEO_V4L1_COMPAT
446 printk("v4l1 ioctl %s, dir=%s (0x%08x)\n",
447 (_IOC_NR(cmd) < V4L1_IOCTLS) ?
448 v4l1_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
452 printk("v4l2 ioctl %s, dir=%s (0x%08x)\n",
453 (_IOC_NR(cmd) < V4L2_IOCTLS) ?
454 v4l2_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
458 printk("unknown ioctl '%c', dir=%s, #%d (0x%08x)\n",
459 _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
464 /* ----------------------------------------------------------------- */
466 /* Helper functions for control handling */
468 /* Check for correctness of the ctrl's value based on the data from
469 struct v4l2_queryctrl and the available menu items. Note that
470 menu_items may be NULL, in that case it is ignored. */
471 int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
472 const char **menu_items)
474 if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED)
476 if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED)
478 if (qctrl->type == V4L2_CTRL_TYPE_BUTTON ||
479 qctrl->type == V4L2_CTRL_TYPE_INTEGER64 ||
480 qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
482 if (ctrl->value < qctrl->minimum || ctrl->value > qctrl->maximum)
484 if (qctrl->type == V4L2_CTRL_TYPE_MENU && menu_items != NULL) {
485 if (menu_items[ctrl->value] == NULL ||
486 menu_items[ctrl->value][0] == '\0')
492 /* Returns NULL or a character pointer array containing the menu for
493 the given control ID. The pointer array ends with a NULL pointer.
494 An empty string signifies a menu entry that is invalid. This allows
495 drivers to disable certain options if it is not supported. */
496 const char **v4l2_ctrl_get_menu(u32 id)
498 static const char *mpeg_audio_sampling_freq[] = {
504 static const char *mpeg_audio_encoding[] = {
510 static const char *mpeg_audio_l1_bitrate[] = {
527 static const char *mpeg_audio_l2_bitrate[] = {
544 static const char *mpeg_audio_l3_bitrate[] = {
561 static const char *mpeg_audio_mode[] = {
568 static const char *mpeg_audio_mode_extension[] = {
575 static const char *mpeg_audio_emphasis[] = {
581 static const char *mpeg_audio_crc[] = {
586 static const char *mpeg_video_encoding[] = {
591 static const char *mpeg_video_aspect[] = {
598 static const char *mpeg_video_bitrate_mode[] = {
603 static const char *mpeg_stream_type[] = {
604 "MPEG-2 Program Stream",
605 "MPEG-2 Transport Stream",
606 "MPEG-1 System Stream",
607 "MPEG-2 DVD-compatible Stream",
608 "MPEG-1 VCD-compatible Stream",
609 "MPEG-2 SVCD-compatible Stream",
612 static const char *mpeg_stream_vbi_fmt[] = {
614 "Private packet, IVTV format",
619 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
620 return mpeg_audio_sampling_freq;
621 case V4L2_CID_MPEG_AUDIO_ENCODING:
622 return mpeg_audio_encoding;
623 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
624 return mpeg_audio_l1_bitrate;
625 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
626 return mpeg_audio_l2_bitrate;
627 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
628 return mpeg_audio_l3_bitrate;
629 case V4L2_CID_MPEG_AUDIO_MODE:
630 return mpeg_audio_mode;
631 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
632 return mpeg_audio_mode_extension;
633 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
634 return mpeg_audio_emphasis;
635 case V4L2_CID_MPEG_AUDIO_CRC:
636 return mpeg_audio_crc;
637 case V4L2_CID_MPEG_VIDEO_ENCODING:
638 return mpeg_video_encoding;
639 case V4L2_CID_MPEG_VIDEO_ASPECT:
640 return mpeg_video_aspect;
641 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
642 return mpeg_video_bitrate_mode;
643 case V4L2_CID_MPEG_STREAM_TYPE:
644 return mpeg_stream_type;
645 case V4L2_CID_MPEG_STREAM_VBI_FMT:
646 return mpeg_stream_vbi_fmt;
652 /* Fill in a struct v4l2_queryctrl */
653 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
660 case V4L2_CID_USER_CLASS: name = "User Controls"; break;
661 case V4L2_CID_AUDIO_VOLUME: name = "Volume"; break;
662 case V4L2_CID_AUDIO_MUTE: name = "Mute"; break;
663 case V4L2_CID_AUDIO_BALANCE: name = "Balance"; break;
664 case V4L2_CID_AUDIO_BASS: name = "Bass"; break;
665 case V4L2_CID_AUDIO_TREBLE: name = "Treble"; break;
666 case V4L2_CID_AUDIO_LOUDNESS: name = "Loudness"; break;
667 case V4L2_CID_BRIGHTNESS: name = "Brightness"; break;
668 case V4L2_CID_CONTRAST: name = "Contrast"; break;
669 case V4L2_CID_SATURATION: name = "Saturation"; break;
670 case V4L2_CID_HUE: name = "Hue"; break;
673 case V4L2_CID_MPEG_CLASS: name = "MPEG Encoder Controls"; break;
674 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: name = "Audio Sampling Frequency"; break;
675 case V4L2_CID_MPEG_AUDIO_ENCODING: name = "Audio Encoding Layer"; break;
676 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: name = "Audio Layer I Bitrate"; break;
677 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: name = "Audio Layer II Bitrate"; break;
678 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: name = "Audio Layer III Bitrate"; break;
679 case V4L2_CID_MPEG_AUDIO_MODE: name = "Audio Stereo Mode"; break;
680 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: name = "Audio Stereo Mode Extension"; break;
681 case V4L2_CID_MPEG_AUDIO_EMPHASIS: name = "Audio Emphasis"; break;
682 case V4L2_CID_MPEG_AUDIO_CRC: name = "Audio CRC"; break;
683 case V4L2_CID_MPEG_VIDEO_ENCODING: name = "Video Encoding"; break;
684 case V4L2_CID_MPEG_VIDEO_ASPECT: name = "Video Aspect"; break;
685 case V4L2_CID_MPEG_VIDEO_B_FRAMES: name = "Video B Frames"; break;
686 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: name = "Video GOP Size"; break;
687 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: name = "Video GOP Closure"; break;
688 case V4L2_CID_MPEG_VIDEO_PULLDOWN: name = "Video Pulldown"; break;
689 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: name = "Video Bitrate Mode"; break;
690 case V4L2_CID_MPEG_VIDEO_BITRATE: name = "Video Bitrate"; break;
691 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: name = "Video Peak Bitrate"; break;
692 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: name = "Video Temporal Decimation"; break;
693 case V4L2_CID_MPEG_STREAM_TYPE: name = "Stream Type"; break;
694 case V4L2_CID_MPEG_STREAM_PID_PMT: name = "Stream PMT Program ID"; break;
695 case V4L2_CID_MPEG_STREAM_PID_AUDIO: name = "Stream Audio Program ID"; break;
696 case V4L2_CID_MPEG_STREAM_PID_VIDEO: name = "Stream Video Program ID"; break;
697 case V4L2_CID_MPEG_STREAM_PID_PCR: name = "Stream PCR Program ID"; break;
698 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: name = "Stream PES Audio ID"; break;
699 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: name = "Stream PES Video ID"; break;
700 case V4L2_CID_MPEG_STREAM_VBI_FMT: name = "Stream VBI Format"; break;
706 case V4L2_CID_AUDIO_MUTE:
707 case V4L2_CID_AUDIO_LOUDNESS:
708 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
709 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
710 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
714 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
715 case V4L2_CID_MPEG_AUDIO_ENCODING:
716 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
717 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
718 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
719 case V4L2_CID_MPEG_AUDIO_MODE:
720 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
721 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
722 case V4L2_CID_MPEG_AUDIO_CRC:
723 case V4L2_CID_MPEG_VIDEO_ENCODING:
724 case V4L2_CID_MPEG_VIDEO_ASPECT:
725 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
726 case V4L2_CID_MPEG_STREAM_TYPE:
727 case V4L2_CID_MPEG_STREAM_VBI_FMT:
728 qctrl->type = V4L2_CTRL_TYPE_MENU;
731 case V4L2_CID_USER_CLASS:
732 case V4L2_CID_MPEG_CLASS:
733 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
734 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
735 min = max = step = def = 0;
738 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
742 case V4L2_CID_MPEG_AUDIO_ENCODING:
743 case V4L2_CID_MPEG_AUDIO_MODE:
744 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
745 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
746 case V4L2_CID_MPEG_STREAM_TYPE:
747 qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
749 case V4L2_CID_AUDIO_VOLUME:
750 case V4L2_CID_AUDIO_BALANCE:
751 case V4L2_CID_AUDIO_BASS:
752 case V4L2_CID_AUDIO_TREBLE:
753 case V4L2_CID_BRIGHTNESS:
754 case V4L2_CID_CONTRAST:
755 case V4L2_CID_SATURATION:
757 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
760 qctrl->minimum = min;
761 qctrl->maximum = max;
763 qctrl->default_value = def;
764 qctrl->reserved[0] = qctrl->reserved[1] = 0;
765 snprintf(qctrl->name, sizeof(qctrl->name), name);
769 /* Fill in a struct v4l2_queryctrl with standard values based on
771 int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
775 case V4L2_CID_USER_CLASS:
776 case V4L2_CID_MPEG_CLASS:
777 return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0);
778 case V4L2_CID_AUDIO_VOLUME:
779 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 58880);
780 case V4L2_CID_AUDIO_MUTE:
781 case V4L2_CID_AUDIO_LOUDNESS:
782 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
783 case V4L2_CID_AUDIO_BALANCE:
784 case V4L2_CID_AUDIO_BASS:
785 case V4L2_CID_AUDIO_TREBLE:
786 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 32768);
787 case V4L2_CID_BRIGHTNESS:
788 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
789 case V4L2_CID_CONTRAST:
790 case V4L2_CID_SATURATION:
791 return v4l2_ctrl_query_fill(qctrl, 0, 127, 1, 64);
793 return v4l2_ctrl_query_fill(qctrl, -128, 127, 1, 0);
796 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
797 return v4l2_ctrl_query_fill(qctrl,
798 V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100,
799 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 1,
800 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
801 case V4L2_CID_MPEG_AUDIO_ENCODING:
802 return v4l2_ctrl_query_fill(qctrl,
803 V4L2_MPEG_AUDIO_ENCODING_LAYER_1,
804 V4L2_MPEG_AUDIO_ENCODING_LAYER_3, 1,
805 V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
806 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
807 return v4l2_ctrl_query_fill(qctrl,
808 V4L2_MPEG_AUDIO_L1_BITRATE_32K,
809 V4L2_MPEG_AUDIO_L1_BITRATE_448K, 1,
810 V4L2_MPEG_AUDIO_L1_BITRATE_256K);
811 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
812 return v4l2_ctrl_query_fill(qctrl,
813 V4L2_MPEG_AUDIO_L2_BITRATE_32K,
814 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
815 V4L2_MPEG_AUDIO_L2_BITRATE_224K);
816 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
817 return v4l2_ctrl_query_fill(qctrl,
818 V4L2_MPEG_AUDIO_L3_BITRATE_32K,
819 V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1,
820 V4L2_MPEG_AUDIO_L3_BITRATE_192K);
821 case V4L2_CID_MPEG_AUDIO_MODE:
822 return v4l2_ctrl_query_fill(qctrl,
823 V4L2_MPEG_AUDIO_MODE_STEREO,
824 V4L2_MPEG_AUDIO_MODE_MONO, 1,
825 V4L2_MPEG_AUDIO_MODE_STEREO);
826 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
827 return v4l2_ctrl_query_fill(qctrl,
828 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4,
829 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 1,
830 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4);
831 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
832 return v4l2_ctrl_query_fill(qctrl,
833 V4L2_MPEG_AUDIO_EMPHASIS_NONE,
834 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 1,
835 V4L2_MPEG_AUDIO_EMPHASIS_NONE);
836 case V4L2_CID_MPEG_AUDIO_CRC:
837 return v4l2_ctrl_query_fill(qctrl,
838 V4L2_MPEG_AUDIO_CRC_NONE,
839 V4L2_MPEG_AUDIO_CRC_CRC16, 1,
840 V4L2_MPEG_AUDIO_CRC_NONE);
841 case V4L2_CID_MPEG_VIDEO_ENCODING:
842 return v4l2_ctrl_query_fill(qctrl,
843 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
844 V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 1,
845 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
846 case V4L2_CID_MPEG_VIDEO_ASPECT:
847 return v4l2_ctrl_query_fill(qctrl,
848 V4L2_MPEG_VIDEO_ASPECT_1x1,
849 V4L2_MPEG_VIDEO_ASPECT_221x100, 1,
850 V4L2_MPEG_VIDEO_ASPECT_4x3);
851 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
852 return v4l2_ctrl_query_fill(qctrl, 0, 33, 1, 2);
853 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
854 return v4l2_ctrl_query_fill(qctrl, 1, 34, 1, 12);
855 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
856 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1);
857 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
858 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
859 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
860 return v4l2_ctrl_query_fill(qctrl,
861 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
862 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
863 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
864 case V4L2_CID_MPEG_VIDEO_BITRATE:
865 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
866 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
867 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
868 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
869 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
870 case V4L2_CID_MPEG_STREAM_TYPE:
871 return v4l2_ctrl_query_fill(qctrl,
872 V4L2_MPEG_STREAM_TYPE_MPEG2_PS,
873 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, 1,
874 V4L2_MPEG_STREAM_TYPE_MPEG2_PS);
875 case V4L2_CID_MPEG_STREAM_PID_PMT:
876 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16);
877 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
878 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260);
879 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
880 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256);
881 case V4L2_CID_MPEG_STREAM_PID_PCR:
882 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259);
883 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO:
884 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
885 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO:
886 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
887 case V4L2_CID_MPEG_STREAM_VBI_FMT:
888 return v4l2_ctrl_query_fill(qctrl,
889 V4L2_MPEG_STREAM_VBI_FMT_NONE,
890 V4L2_MPEG_STREAM_VBI_FMT_IVTV, 1,
891 V4L2_MPEG_STREAM_VBI_FMT_NONE);
897 /* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
898 the menu. The qctrl pointer may be NULL, in which case it is ignored. */
899 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
900 const char **menu_items)
904 if (menu_items == NULL ||
905 (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum)))
907 for (i = 0; i < qmenu->index && menu_items[i]; i++) ;
908 if (menu_items[i] == NULL || menu_items[i][0] == '\0')
910 snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]);
915 /* ctrl_classes points to an array of u32 pointers, the last element is
916 a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
917 Each array must be sorted low to high and belong to the same control
918 class. The array of u32 pointer must also be sorted, from low class IDs
921 This function returns the first ID that follows after the given ID.
922 When no more controls are available 0 is returned. */
923 u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
928 /* if no query is desired, then just return the control ID */
929 if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0)
931 if (ctrl_classes == NULL)
933 id &= V4L2_CTRL_ID_MASK;
934 ctrl_class = V4L2_CTRL_ID2CLASS(id);
935 id++; /* select next control */
936 /* find first class that matches (or is greater than) the class of
938 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) < ctrl_class)
940 /* no more classes */
941 if (*ctrl_classes == NULL)
943 pctrl = *ctrl_classes;
944 /* find first ctrl within the class that is >= ID */
945 while (*pctrl && *pctrl < id) pctrl++;
948 /* we are at the end of the controls of the current class. */
949 /* continue with next class if available */
951 if (*ctrl_classes == NULL)
953 return **ctrl_classes;
956 int v4l2_chip_match_i2c_client(struct i2c_client *c, u32 match_type, u32 match_chip)
958 switch (match_type) {
959 case V4L2_CHIP_MATCH_I2C_DRIVER:
960 return (c != NULL && c->driver != NULL && c->driver->id == match_chip);
961 case V4L2_CHIP_MATCH_I2C_ADDR:
962 return (c != NULL && c->addr == match_chip);
968 int v4l2_chip_match_host(u32 match_type, u32 match_chip)
970 switch (match_type) {
971 case V4L2_CHIP_MATCH_HOST:
972 return match_chip == 0;
978 /* ----------------------------------------------------------------- */
980 EXPORT_SYMBOL(v4l2_norm_to_name);
981 EXPORT_SYMBOL(v4l2_video_std_construct);
983 EXPORT_SYMBOL(v4l2_prio_init);
984 EXPORT_SYMBOL(v4l2_prio_change);
985 EXPORT_SYMBOL(v4l2_prio_open);
986 EXPORT_SYMBOL(v4l2_prio_close);
987 EXPORT_SYMBOL(v4l2_prio_max);
988 EXPORT_SYMBOL(v4l2_prio_check);
990 EXPORT_SYMBOL(v4l2_field_names);
991 EXPORT_SYMBOL(v4l2_type_names);
992 EXPORT_SYMBOL(v4l_printk_ioctl);
994 EXPORT_SYMBOL(v4l2_ctrl_next);
995 EXPORT_SYMBOL(v4l2_ctrl_check);
996 EXPORT_SYMBOL(v4l2_ctrl_get_menu);
997 EXPORT_SYMBOL(v4l2_ctrl_query_menu);
998 EXPORT_SYMBOL(v4l2_ctrl_query_fill);
999 EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);
1001 EXPORT_SYMBOL(v4l2_chip_match_i2c_client);
1002 EXPORT_SYMBOL(v4l2_chip_match_host);