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>
51 #include <linux/string.h>
52 #include <linux/errno.h>
53 #include <linux/i2c.h>
54 #include <asm/uaccess.h>
55 #include <asm/system.h>
56 #include <asm/pgtable.h>
58 #include <asm/div64.h>
59 #define __OLD_VIDIOC_ /* To allow fixing old calls*/
60 #include <media/v4l2-common.h>
61 #include <media/v4l2-chip-ident.h>
64 #include <linux/kmod.h>
67 #include <linux/videodev2.h>
69 MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
70 MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers");
71 MODULE_LICENSE("GPL");
75 * V 4 L 2 D R I V E R H E L P E R A P I
80 * Video Standard Operations (contributed by Michael Schimek)
84 /* ----------------------------------------------------------------- */
85 /* priority handling */
87 #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND || \
88 val == V4L2_PRIORITY_INTERACTIVE || \
89 val == V4L2_PRIORITY_RECORD)
91 int v4l2_prio_init(struct v4l2_prio_state *global)
93 memset(global,0,sizeof(*global));
96 EXPORT_SYMBOL(v4l2_prio_init);
98 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
99 enum v4l2_priority new)
101 if (!V4L2_PRIO_VALID(new))
106 atomic_inc(&global->prios[new]);
107 if (V4L2_PRIO_VALID(*local))
108 atomic_dec(&global->prios[*local]);
112 EXPORT_SYMBOL(v4l2_prio_change);
114 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
116 return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
118 EXPORT_SYMBOL(v4l2_prio_open);
120 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
122 if (V4L2_PRIO_VALID(*local))
123 atomic_dec(&global->prios[*local]);
126 EXPORT_SYMBOL(v4l2_prio_close);
128 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
130 if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
131 return V4L2_PRIORITY_RECORD;
132 if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
133 return V4L2_PRIORITY_INTERACTIVE;
134 if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
135 return V4L2_PRIORITY_BACKGROUND;
136 return V4L2_PRIORITY_UNSET;
138 EXPORT_SYMBOL(v4l2_prio_max);
140 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
142 if (*local < v4l2_prio_max(global))
146 EXPORT_SYMBOL(v4l2_prio_check);
148 /* ----------------------------------------------------------------- */
150 /* Helper functions for control handling */
152 /* Check for correctness of the ctrl's value based on the data from
153 struct v4l2_queryctrl and the available menu items. Note that
154 menu_items may be NULL, in that case it is ignored. */
155 int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
156 const char **menu_items)
158 if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED)
160 if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED)
162 if (qctrl->type == V4L2_CTRL_TYPE_BUTTON ||
163 qctrl->type == V4L2_CTRL_TYPE_INTEGER64 ||
164 qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
166 if (ctrl->value < qctrl->minimum || ctrl->value > qctrl->maximum)
168 if (qctrl->type == V4L2_CTRL_TYPE_MENU && menu_items != NULL) {
169 if (menu_items[ctrl->value] == NULL ||
170 menu_items[ctrl->value][0] == '\0')
175 EXPORT_SYMBOL(v4l2_ctrl_check);
177 /* Returns NULL or a character pointer array containing the menu for
178 the given control ID. The pointer array ends with a NULL pointer.
179 An empty string signifies a menu entry that is invalid. This allows
180 drivers to disable certain options if it is not supported. */
181 const char **v4l2_ctrl_get_menu(u32 id)
183 static const char *mpeg_audio_sampling_freq[] = {
189 static const char *mpeg_audio_encoding[] = {
192 "MPEG-1/2 Layer III",
197 static const char *mpeg_audio_l1_bitrate[] = {
214 static const char *mpeg_audio_l2_bitrate[] = {
231 static const char *mpeg_audio_l3_bitrate[] = {
248 static const char *mpeg_audio_ac3_bitrate[] = {
270 static const char *mpeg_audio_mode[] = {
277 static const char *mpeg_audio_mode_extension[] = {
284 static const char *mpeg_audio_emphasis[] = {
290 static const char *mpeg_audio_crc[] = {
295 static const char *mpeg_video_encoding[] = {
301 static const char *mpeg_video_aspect[] = {
308 static const char *mpeg_video_bitrate_mode[] = {
313 static const char *mpeg_stream_type[] = {
314 "MPEG-2 Program Stream",
315 "MPEG-2 Transport Stream",
316 "MPEG-1 System Stream",
317 "MPEG-2 DVD-compatible Stream",
318 "MPEG-1 VCD-compatible Stream",
319 "MPEG-2 SVCD-compatible Stream",
322 static const char *mpeg_stream_vbi_fmt[] = {
324 "Private packet, IVTV format",
329 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
330 return mpeg_audio_sampling_freq;
331 case V4L2_CID_MPEG_AUDIO_ENCODING:
332 return mpeg_audio_encoding;
333 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
334 return mpeg_audio_l1_bitrate;
335 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
336 return mpeg_audio_l2_bitrate;
337 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
338 return mpeg_audio_l3_bitrate;
339 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
340 return mpeg_audio_ac3_bitrate;
341 case V4L2_CID_MPEG_AUDIO_MODE:
342 return mpeg_audio_mode;
343 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
344 return mpeg_audio_mode_extension;
345 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
346 return mpeg_audio_emphasis;
347 case V4L2_CID_MPEG_AUDIO_CRC:
348 return mpeg_audio_crc;
349 case V4L2_CID_MPEG_VIDEO_ENCODING:
350 return mpeg_video_encoding;
351 case V4L2_CID_MPEG_VIDEO_ASPECT:
352 return mpeg_video_aspect;
353 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
354 return mpeg_video_bitrate_mode;
355 case V4L2_CID_MPEG_STREAM_TYPE:
356 return mpeg_stream_type;
357 case V4L2_CID_MPEG_STREAM_VBI_FMT:
358 return mpeg_stream_vbi_fmt;
363 EXPORT_SYMBOL(v4l2_ctrl_get_menu);
365 /* Return the control name. */
366 const char *v4l2_ctrl_get_name(u32 id)
370 case V4L2_CID_USER_CLASS: return "User Controls";
371 case V4L2_CID_AUDIO_VOLUME: return "Volume";
372 case V4L2_CID_AUDIO_MUTE: return "Mute";
373 case V4L2_CID_AUDIO_BALANCE: return "Balance";
374 case V4L2_CID_AUDIO_BASS: return "Bass";
375 case V4L2_CID_AUDIO_TREBLE: return "Treble";
376 case V4L2_CID_AUDIO_LOUDNESS: return "Loudness";
377 case V4L2_CID_BRIGHTNESS: return "Brightness";
378 case V4L2_CID_CONTRAST: return "Contrast";
379 case V4L2_CID_SATURATION: return "Saturation";
380 case V4L2_CID_HUE: return "Hue";
383 case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls";
384 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
385 case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding";
386 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate";
387 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate";
388 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate";
389 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate";
390 case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode";
391 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
392 case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis";
393 case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC";
394 case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute";
395 case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding";
396 case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect";
397 case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames";
398 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size";
399 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure";
400 case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown";
401 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode";
402 case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate";
403 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate";
404 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
405 case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute";
406 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV";
407 case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type";
408 case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID";
409 case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID";
410 case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID";
411 case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID";
412 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
413 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
414 case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format";
420 EXPORT_SYMBOL(v4l2_ctrl_get_name);
422 /* Fill in a struct v4l2_queryctrl */
423 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
425 const char *name = v4l2_ctrl_get_name(qctrl->id);
432 case V4L2_CID_AUDIO_MUTE:
433 case V4L2_CID_AUDIO_LOUDNESS:
434 case V4L2_CID_MPEG_AUDIO_MUTE:
435 case V4L2_CID_MPEG_VIDEO_MUTE:
436 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
437 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
438 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
442 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
443 case V4L2_CID_MPEG_AUDIO_ENCODING:
444 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
445 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
446 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
447 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
448 case V4L2_CID_MPEG_AUDIO_MODE:
449 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
450 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
451 case V4L2_CID_MPEG_AUDIO_CRC:
452 case V4L2_CID_MPEG_VIDEO_ENCODING:
453 case V4L2_CID_MPEG_VIDEO_ASPECT:
454 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
455 case V4L2_CID_MPEG_STREAM_TYPE:
456 case V4L2_CID_MPEG_STREAM_VBI_FMT:
457 qctrl->type = V4L2_CTRL_TYPE_MENU;
460 case V4L2_CID_USER_CLASS:
461 case V4L2_CID_MPEG_CLASS:
462 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
463 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
464 min = max = step = def = 0;
467 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
471 case V4L2_CID_MPEG_AUDIO_ENCODING:
472 case V4L2_CID_MPEG_AUDIO_MODE:
473 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
474 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
475 case V4L2_CID_MPEG_STREAM_TYPE:
476 qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
478 case V4L2_CID_AUDIO_VOLUME:
479 case V4L2_CID_AUDIO_BALANCE:
480 case V4L2_CID_AUDIO_BASS:
481 case V4L2_CID_AUDIO_TREBLE:
482 case V4L2_CID_BRIGHTNESS:
483 case V4L2_CID_CONTRAST:
484 case V4L2_CID_SATURATION:
486 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
489 qctrl->minimum = min;
490 qctrl->maximum = max;
492 qctrl->default_value = def;
493 qctrl->reserved[0] = qctrl->reserved[1] = 0;
494 snprintf(qctrl->name, sizeof(qctrl->name), name);
497 EXPORT_SYMBOL(v4l2_ctrl_query_fill);
499 /* Fill in a struct v4l2_queryctrl with standard values based on
501 int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
505 case V4L2_CID_USER_CLASS:
506 case V4L2_CID_MPEG_CLASS:
507 return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0);
508 case V4L2_CID_AUDIO_VOLUME:
509 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 58880);
510 case V4L2_CID_AUDIO_MUTE:
511 case V4L2_CID_AUDIO_LOUDNESS:
512 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
513 case V4L2_CID_AUDIO_BALANCE:
514 case V4L2_CID_AUDIO_BASS:
515 case V4L2_CID_AUDIO_TREBLE:
516 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 32768);
517 case V4L2_CID_BRIGHTNESS:
518 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
519 case V4L2_CID_CONTRAST:
520 case V4L2_CID_SATURATION:
521 return v4l2_ctrl_query_fill(qctrl, 0, 127, 1, 64);
523 return v4l2_ctrl_query_fill(qctrl, -128, 127, 1, 0);
526 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
527 return v4l2_ctrl_query_fill(qctrl,
528 V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100,
529 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 1,
530 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
531 case V4L2_CID_MPEG_AUDIO_ENCODING:
532 return v4l2_ctrl_query_fill(qctrl,
533 V4L2_MPEG_AUDIO_ENCODING_LAYER_1,
534 V4L2_MPEG_AUDIO_ENCODING_AC3, 1,
535 V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
536 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
537 return v4l2_ctrl_query_fill(qctrl,
538 V4L2_MPEG_AUDIO_L1_BITRATE_32K,
539 V4L2_MPEG_AUDIO_L1_BITRATE_448K, 1,
540 V4L2_MPEG_AUDIO_L1_BITRATE_256K);
541 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
542 return v4l2_ctrl_query_fill(qctrl,
543 V4L2_MPEG_AUDIO_L2_BITRATE_32K,
544 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
545 V4L2_MPEG_AUDIO_L2_BITRATE_224K);
546 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
547 return v4l2_ctrl_query_fill(qctrl,
548 V4L2_MPEG_AUDIO_L3_BITRATE_32K,
549 V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1,
550 V4L2_MPEG_AUDIO_L3_BITRATE_192K);
551 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
552 return v4l2_ctrl_query_fill(qctrl,
553 V4L2_MPEG_AUDIO_AC3_BITRATE_32K,
554 V4L2_MPEG_AUDIO_AC3_BITRATE_640K, 1,
555 V4L2_MPEG_AUDIO_AC3_BITRATE_384K);
556 case V4L2_CID_MPEG_AUDIO_MODE:
557 return v4l2_ctrl_query_fill(qctrl,
558 V4L2_MPEG_AUDIO_MODE_STEREO,
559 V4L2_MPEG_AUDIO_MODE_MONO, 1,
560 V4L2_MPEG_AUDIO_MODE_STEREO);
561 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
562 return v4l2_ctrl_query_fill(qctrl,
563 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4,
564 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 1,
565 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4);
566 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
567 return v4l2_ctrl_query_fill(qctrl,
568 V4L2_MPEG_AUDIO_EMPHASIS_NONE,
569 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 1,
570 V4L2_MPEG_AUDIO_EMPHASIS_NONE);
571 case V4L2_CID_MPEG_AUDIO_CRC:
572 return v4l2_ctrl_query_fill(qctrl,
573 V4L2_MPEG_AUDIO_CRC_NONE,
574 V4L2_MPEG_AUDIO_CRC_CRC16, 1,
575 V4L2_MPEG_AUDIO_CRC_NONE);
576 case V4L2_CID_MPEG_AUDIO_MUTE:
577 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
578 case V4L2_CID_MPEG_VIDEO_ENCODING:
579 return v4l2_ctrl_query_fill(qctrl,
580 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
581 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
582 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
583 case V4L2_CID_MPEG_VIDEO_ASPECT:
584 return v4l2_ctrl_query_fill(qctrl,
585 V4L2_MPEG_VIDEO_ASPECT_1x1,
586 V4L2_MPEG_VIDEO_ASPECT_221x100, 1,
587 V4L2_MPEG_VIDEO_ASPECT_4x3);
588 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
589 return v4l2_ctrl_query_fill(qctrl, 0, 33, 1, 2);
590 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
591 return v4l2_ctrl_query_fill(qctrl, 1, 34, 1, 12);
592 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
593 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1);
594 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
595 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
596 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
597 return v4l2_ctrl_query_fill(qctrl,
598 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
599 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
600 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
601 case V4L2_CID_MPEG_VIDEO_BITRATE:
602 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
603 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
604 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
605 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
606 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
607 case V4L2_CID_MPEG_VIDEO_MUTE:
608 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
609 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: /* Init YUV (really YCbCr) to black */
610 return v4l2_ctrl_query_fill(qctrl, 0, 0xffffff, 1, 0x008080);
611 case V4L2_CID_MPEG_STREAM_TYPE:
612 return v4l2_ctrl_query_fill(qctrl,
613 V4L2_MPEG_STREAM_TYPE_MPEG2_PS,
614 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, 1,
615 V4L2_MPEG_STREAM_TYPE_MPEG2_PS);
616 case V4L2_CID_MPEG_STREAM_PID_PMT:
617 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16);
618 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
619 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260);
620 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
621 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256);
622 case V4L2_CID_MPEG_STREAM_PID_PCR:
623 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259);
624 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO:
625 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
626 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO:
627 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
628 case V4L2_CID_MPEG_STREAM_VBI_FMT:
629 return v4l2_ctrl_query_fill(qctrl,
630 V4L2_MPEG_STREAM_VBI_FMT_NONE,
631 V4L2_MPEG_STREAM_VBI_FMT_IVTV, 1,
632 V4L2_MPEG_STREAM_VBI_FMT_NONE);
637 EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);
639 /* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
640 the menu. The qctrl pointer may be NULL, in which case it is ignored. */
641 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
642 const char **menu_items)
646 if (menu_items == NULL ||
647 (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum)))
649 for (i = 0; i < qmenu->index && menu_items[i]; i++) ;
650 if (menu_items[i] == NULL || menu_items[i][0] == '\0')
652 snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]);
656 EXPORT_SYMBOL(v4l2_ctrl_query_menu);
658 /* ctrl_classes points to an array of u32 pointers, the last element is
659 a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
660 Each array must be sorted low to high and belong to the same control
661 class. The array of u32 pointer must also be sorted, from low class IDs
664 This function returns the first ID that follows after the given ID.
665 When no more controls are available 0 is returned. */
666 u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
668 u32 ctrl_class = V4L2_CTRL_ID2CLASS(id);
671 if (ctrl_classes == NULL)
674 /* if no query is desired, then check if the ID is part of ctrl_classes */
675 if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0) {
677 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) != ctrl_class)
679 if (*ctrl_classes == NULL)
681 pctrl = *ctrl_classes;
682 /* find control ID */
683 while (*pctrl && *pctrl != id) pctrl++;
684 return *pctrl ? id : 0;
686 id &= V4L2_CTRL_ID_MASK;
687 id++; /* select next control */
688 /* find first class that matches (or is greater than) the class of
690 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) < ctrl_class)
692 /* no more classes */
693 if (*ctrl_classes == NULL)
695 pctrl = *ctrl_classes;
696 /* find first ctrl within the class that is >= ID */
697 while (*pctrl && *pctrl < id) pctrl++;
700 /* we are at the end of the controls of the current class. */
701 /* continue with next class if available */
703 if (*ctrl_classes == NULL)
705 return **ctrl_classes;
707 EXPORT_SYMBOL(v4l2_ctrl_next);
709 int v4l2_chip_match_host(u32 match_type, u32 match_chip)
711 switch (match_type) {
712 case V4L2_CHIP_MATCH_HOST:
713 return match_chip == 0;
718 EXPORT_SYMBOL(v4l2_chip_match_host);
720 #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
721 int v4l2_chip_match_i2c_client(struct i2c_client *c, u32 match_type, u32 match_chip)
723 switch (match_type) {
724 case V4L2_CHIP_MATCH_I2C_DRIVER:
725 return (c != NULL && c->driver != NULL && c->driver->id == match_chip);
726 case V4L2_CHIP_MATCH_I2C_ADDR:
727 return (c != NULL && c->addr == match_chip);
732 EXPORT_SYMBOL(v4l2_chip_match_i2c_client);
734 int v4l2_chip_ident_i2c_client(struct i2c_client *c, struct v4l2_chip_ident *chip,
735 u32 ident, u32 revision)
737 if (!v4l2_chip_match_i2c_client(c, chip->match_type, chip->match_chip))
739 if (chip->ident == V4L2_IDENT_NONE) {
741 chip->revision = revision;
744 chip->ident = V4L2_IDENT_AMBIGUOUS;
749 EXPORT_SYMBOL(v4l2_chip_ident_i2c_client);
751 /* ----------------------------------------------------------------- */
753 /* Helper function for I2C legacy drivers */
755 int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver,
757 int (*probe)(struct i2c_client *, const struct i2c_device_id *))
759 struct i2c_client *client;
762 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
766 client->addr = address;
767 client->adapter = adapter;
768 client->driver = driver;
769 strlcpy(client->name, name, sizeof(client->name));
771 err = probe(client, NULL);
773 i2c_attach_client(client);
777 return err != -ENOMEM ? 0 : err;
779 EXPORT_SYMBOL(v4l2_i2c_attach);