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@lxorguk.ukuu.org.uk>
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>
63 #include <linux/videodev2.h>
65 MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
66 MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers");
67 MODULE_LICENSE("GPL");
71 * V 4 L 2 D R I V E R H E L P E R A P I
76 * Video Standard Operations (contributed by Michael Schimek)
80 /* ----------------------------------------------------------------- */
81 /* priority handling */
83 #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND || \
84 val == V4L2_PRIORITY_INTERACTIVE || \
85 val == V4L2_PRIORITY_RECORD)
87 int v4l2_prio_init(struct v4l2_prio_state *global)
89 memset(global,0,sizeof(*global));
92 EXPORT_SYMBOL(v4l2_prio_init);
94 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
95 enum v4l2_priority new)
97 if (!V4L2_PRIO_VALID(new))
102 atomic_inc(&global->prios[new]);
103 if (V4L2_PRIO_VALID(*local))
104 atomic_dec(&global->prios[*local]);
108 EXPORT_SYMBOL(v4l2_prio_change);
110 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
112 return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
114 EXPORT_SYMBOL(v4l2_prio_open);
116 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
118 if (V4L2_PRIO_VALID(*local))
119 atomic_dec(&global->prios[*local]);
122 EXPORT_SYMBOL(v4l2_prio_close);
124 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
126 if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
127 return V4L2_PRIORITY_RECORD;
128 if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
129 return V4L2_PRIORITY_INTERACTIVE;
130 if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
131 return V4L2_PRIORITY_BACKGROUND;
132 return V4L2_PRIORITY_UNSET;
134 EXPORT_SYMBOL(v4l2_prio_max);
136 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
138 if (*local < v4l2_prio_max(global))
142 EXPORT_SYMBOL(v4l2_prio_check);
144 /* ----------------------------------------------------------------- */
146 /* Helper functions for control handling */
148 /* Check for correctness of the ctrl's value based on the data from
149 struct v4l2_queryctrl and the available menu items. Note that
150 menu_items may be NULL, in that case it is ignored. */
151 int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
152 const char **menu_items)
154 if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED)
156 if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED)
158 if (qctrl->type == V4L2_CTRL_TYPE_BUTTON ||
159 qctrl->type == V4L2_CTRL_TYPE_INTEGER64 ||
160 qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
162 if (ctrl->value < qctrl->minimum || ctrl->value > qctrl->maximum)
164 if (qctrl->type == V4L2_CTRL_TYPE_MENU && menu_items != NULL) {
165 if (menu_items[ctrl->value] == NULL ||
166 menu_items[ctrl->value][0] == '\0')
171 EXPORT_SYMBOL(v4l2_ctrl_check);
173 /* Returns NULL or a character pointer array containing the menu for
174 the given control ID. The pointer array ends with a NULL pointer.
175 An empty string signifies a menu entry that is invalid. This allows
176 drivers to disable certain options if it is not supported. */
177 const char **v4l2_ctrl_get_menu(u32 id)
179 static const char *mpeg_audio_sampling_freq[] = {
185 static const char *mpeg_audio_encoding[] = {
188 "MPEG-1/2 Layer III",
193 static const char *mpeg_audio_l1_bitrate[] = {
210 static const char *mpeg_audio_l2_bitrate[] = {
227 static const char *mpeg_audio_l3_bitrate[] = {
244 static const char *mpeg_audio_ac3_bitrate[] = {
266 static const char *mpeg_audio_mode[] = {
273 static const char *mpeg_audio_mode_extension[] = {
280 static const char *mpeg_audio_emphasis[] = {
286 static const char *mpeg_audio_crc[] = {
291 static const char *mpeg_video_encoding[] = {
297 static const char *mpeg_video_aspect[] = {
304 static const char *mpeg_video_bitrate_mode[] = {
309 static const char *mpeg_stream_type[] = {
310 "MPEG-2 Program Stream",
311 "MPEG-2 Transport Stream",
312 "MPEG-1 System Stream",
313 "MPEG-2 DVD-compatible Stream",
314 "MPEG-1 VCD-compatible Stream",
315 "MPEG-2 SVCD-compatible Stream",
318 static const char *mpeg_stream_vbi_fmt[] = {
320 "Private packet, IVTV format",
325 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
326 return mpeg_audio_sampling_freq;
327 case V4L2_CID_MPEG_AUDIO_ENCODING:
328 return mpeg_audio_encoding;
329 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
330 return mpeg_audio_l1_bitrate;
331 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
332 return mpeg_audio_l2_bitrate;
333 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
334 return mpeg_audio_l3_bitrate;
335 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
336 return mpeg_audio_ac3_bitrate;
337 case V4L2_CID_MPEG_AUDIO_MODE:
338 return mpeg_audio_mode;
339 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
340 return mpeg_audio_mode_extension;
341 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
342 return mpeg_audio_emphasis;
343 case V4L2_CID_MPEG_AUDIO_CRC:
344 return mpeg_audio_crc;
345 case V4L2_CID_MPEG_VIDEO_ENCODING:
346 return mpeg_video_encoding;
347 case V4L2_CID_MPEG_VIDEO_ASPECT:
348 return mpeg_video_aspect;
349 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
350 return mpeg_video_bitrate_mode;
351 case V4L2_CID_MPEG_STREAM_TYPE:
352 return mpeg_stream_type;
353 case V4L2_CID_MPEG_STREAM_VBI_FMT:
354 return mpeg_stream_vbi_fmt;
359 EXPORT_SYMBOL(v4l2_ctrl_get_menu);
361 /* Return the control name. */
362 const char *v4l2_ctrl_get_name(u32 id)
366 case V4L2_CID_USER_CLASS: return "User Controls";
367 case V4L2_CID_AUDIO_VOLUME: return "Volume";
368 case V4L2_CID_AUDIO_MUTE: return "Mute";
369 case V4L2_CID_AUDIO_BALANCE: return "Balance";
370 case V4L2_CID_AUDIO_BASS: return "Bass";
371 case V4L2_CID_AUDIO_TREBLE: return "Treble";
372 case V4L2_CID_AUDIO_LOUDNESS: return "Loudness";
373 case V4L2_CID_BRIGHTNESS: return "Brightness";
374 case V4L2_CID_CONTRAST: return "Contrast";
375 case V4L2_CID_SATURATION: return "Saturation";
376 case V4L2_CID_HUE: return "Hue";
379 case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls";
380 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
381 case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding";
382 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate";
383 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate";
384 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate";
385 case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate";
386 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate";
387 case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode";
388 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
389 case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis";
390 case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC";
391 case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute";
392 case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding";
393 case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect";
394 case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames";
395 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size";
396 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure";
397 case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown";
398 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode";
399 case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate";
400 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate";
401 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
402 case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute";
403 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV";
404 case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type";
405 case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID";
406 case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID";
407 case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID";
408 case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID";
409 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
410 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
411 case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format";
417 EXPORT_SYMBOL(v4l2_ctrl_get_name);
419 /* Fill in a struct v4l2_queryctrl */
420 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
422 const char *name = v4l2_ctrl_get_name(qctrl->id);
429 case V4L2_CID_AUDIO_MUTE:
430 case V4L2_CID_AUDIO_LOUDNESS:
431 case V4L2_CID_MPEG_AUDIO_MUTE:
432 case V4L2_CID_MPEG_VIDEO_MUTE:
433 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
434 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
435 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
439 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
440 case V4L2_CID_MPEG_AUDIO_ENCODING:
441 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
442 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
443 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
444 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
445 case V4L2_CID_MPEG_AUDIO_MODE:
446 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
447 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
448 case V4L2_CID_MPEG_AUDIO_CRC:
449 case V4L2_CID_MPEG_VIDEO_ENCODING:
450 case V4L2_CID_MPEG_VIDEO_ASPECT:
451 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
452 case V4L2_CID_MPEG_STREAM_TYPE:
453 case V4L2_CID_MPEG_STREAM_VBI_FMT:
454 qctrl->type = V4L2_CTRL_TYPE_MENU;
457 case V4L2_CID_USER_CLASS:
458 case V4L2_CID_MPEG_CLASS:
459 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
460 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
461 min = max = step = def = 0;
464 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
468 case V4L2_CID_MPEG_AUDIO_ENCODING:
469 case V4L2_CID_MPEG_AUDIO_MODE:
470 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
471 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
472 case V4L2_CID_MPEG_STREAM_TYPE:
473 qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
475 case V4L2_CID_AUDIO_VOLUME:
476 case V4L2_CID_AUDIO_BALANCE:
477 case V4L2_CID_AUDIO_BASS:
478 case V4L2_CID_AUDIO_TREBLE:
479 case V4L2_CID_BRIGHTNESS:
480 case V4L2_CID_CONTRAST:
481 case V4L2_CID_SATURATION:
483 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
486 qctrl->minimum = min;
487 qctrl->maximum = max;
489 qctrl->default_value = def;
490 qctrl->reserved[0] = qctrl->reserved[1] = 0;
491 snprintf(qctrl->name, sizeof(qctrl->name), name);
494 EXPORT_SYMBOL(v4l2_ctrl_query_fill);
496 /* Fill in a struct v4l2_queryctrl with standard values based on
498 int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
502 case V4L2_CID_USER_CLASS:
503 case V4L2_CID_MPEG_CLASS:
504 return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0);
505 case V4L2_CID_AUDIO_VOLUME:
506 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 58880);
507 case V4L2_CID_AUDIO_MUTE:
508 case V4L2_CID_AUDIO_LOUDNESS:
509 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
510 case V4L2_CID_AUDIO_BALANCE:
511 case V4L2_CID_AUDIO_BASS:
512 case V4L2_CID_AUDIO_TREBLE:
513 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 32768);
514 case V4L2_CID_BRIGHTNESS:
515 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
516 case V4L2_CID_CONTRAST:
517 case V4L2_CID_SATURATION:
518 return v4l2_ctrl_query_fill(qctrl, 0, 127, 1, 64);
520 return v4l2_ctrl_query_fill(qctrl, -128, 127, 1, 0);
523 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
524 return v4l2_ctrl_query_fill(qctrl,
525 V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100,
526 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 1,
527 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
528 case V4L2_CID_MPEG_AUDIO_ENCODING:
529 return v4l2_ctrl_query_fill(qctrl,
530 V4L2_MPEG_AUDIO_ENCODING_LAYER_1,
531 V4L2_MPEG_AUDIO_ENCODING_AC3, 1,
532 V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
533 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
534 return v4l2_ctrl_query_fill(qctrl,
535 V4L2_MPEG_AUDIO_L1_BITRATE_32K,
536 V4L2_MPEG_AUDIO_L1_BITRATE_448K, 1,
537 V4L2_MPEG_AUDIO_L1_BITRATE_256K);
538 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
539 return v4l2_ctrl_query_fill(qctrl,
540 V4L2_MPEG_AUDIO_L2_BITRATE_32K,
541 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
542 V4L2_MPEG_AUDIO_L2_BITRATE_224K);
543 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
544 return v4l2_ctrl_query_fill(qctrl,
545 V4L2_MPEG_AUDIO_L3_BITRATE_32K,
546 V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1,
547 V4L2_MPEG_AUDIO_L3_BITRATE_192K);
548 case V4L2_CID_MPEG_AUDIO_AAC_BITRATE:
549 return v4l2_ctrl_query_fill(qctrl, 0, 6400, 1, 3200000);
550 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
551 return v4l2_ctrl_query_fill(qctrl,
552 V4L2_MPEG_AUDIO_AC3_BITRATE_32K,
553 V4L2_MPEG_AUDIO_AC3_BITRATE_640K, 1,
554 V4L2_MPEG_AUDIO_AC3_BITRATE_384K);
555 case V4L2_CID_MPEG_AUDIO_MODE:
556 return v4l2_ctrl_query_fill(qctrl,
557 V4L2_MPEG_AUDIO_MODE_STEREO,
558 V4L2_MPEG_AUDIO_MODE_MONO, 1,
559 V4L2_MPEG_AUDIO_MODE_STEREO);
560 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
561 return v4l2_ctrl_query_fill(qctrl,
562 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4,
563 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 1,
564 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4);
565 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
566 return v4l2_ctrl_query_fill(qctrl,
567 V4L2_MPEG_AUDIO_EMPHASIS_NONE,
568 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 1,
569 V4L2_MPEG_AUDIO_EMPHASIS_NONE);
570 case V4L2_CID_MPEG_AUDIO_CRC:
571 return v4l2_ctrl_query_fill(qctrl,
572 V4L2_MPEG_AUDIO_CRC_NONE,
573 V4L2_MPEG_AUDIO_CRC_CRC16, 1,
574 V4L2_MPEG_AUDIO_CRC_NONE);
575 case V4L2_CID_MPEG_AUDIO_MUTE:
576 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
577 case V4L2_CID_MPEG_VIDEO_ENCODING:
578 return v4l2_ctrl_query_fill(qctrl,
579 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
580 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
581 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
582 case V4L2_CID_MPEG_VIDEO_ASPECT:
583 return v4l2_ctrl_query_fill(qctrl,
584 V4L2_MPEG_VIDEO_ASPECT_1x1,
585 V4L2_MPEG_VIDEO_ASPECT_221x100, 1,
586 V4L2_MPEG_VIDEO_ASPECT_4x3);
587 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
588 return v4l2_ctrl_query_fill(qctrl, 0, 33, 1, 2);
589 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
590 return v4l2_ctrl_query_fill(qctrl, 1, 34, 1, 12);
591 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
592 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1);
593 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
594 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
595 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
596 return v4l2_ctrl_query_fill(qctrl,
597 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
598 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
599 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
600 case V4L2_CID_MPEG_VIDEO_BITRATE:
601 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
602 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
603 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
604 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
605 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
606 case V4L2_CID_MPEG_VIDEO_MUTE:
607 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
608 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: /* Init YUV (really YCbCr) to black */
609 return v4l2_ctrl_query_fill(qctrl, 0, 0xffffff, 1, 0x008080);
610 case V4L2_CID_MPEG_STREAM_TYPE:
611 return v4l2_ctrl_query_fill(qctrl,
612 V4L2_MPEG_STREAM_TYPE_MPEG2_PS,
613 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, 1,
614 V4L2_MPEG_STREAM_TYPE_MPEG2_PS);
615 case V4L2_CID_MPEG_STREAM_PID_PMT:
616 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16);
617 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
618 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260);
619 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
620 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256);
621 case V4L2_CID_MPEG_STREAM_PID_PCR:
622 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259);
623 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO:
624 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
625 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO:
626 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
627 case V4L2_CID_MPEG_STREAM_VBI_FMT:
628 return v4l2_ctrl_query_fill(qctrl,
629 V4L2_MPEG_STREAM_VBI_FMT_NONE,
630 V4L2_MPEG_STREAM_VBI_FMT_IVTV, 1,
631 V4L2_MPEG_STREAM_VBI_FMT_NONE);
636 EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);
638 /* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
639 the menu. The qctrl pointer may be NULL, in which case it is ignored.
640 If menu_items is NULL, then the menu items are retrieved using
641 v4l2_ctrl_get_menu. */
642 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
643 const char **menu_items)
648 if (menu_items == NULL)
649 menu_items = v4l2_ctrl_get_menu(qmenu->id);
650 if (menu_items == NULL ||
651 (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum)))
653 for (i = 0; i < qmenu->index && menu_items[i]; i++) ;
654 if (menu_items[i] == NULL || menu_items[i][0] == '\0')
656 snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]);
659 EXPORT_SYMBOL(v4l2_ctrl_query_menu);
661 /* Fill in a struct v4l2_querymenu based on the specified array of valid
662 menu items (terminated by V4L2_CTRL_MENU_IDS_END).
663 Use this if there are 'holes' in the list of valid menu items. */
664 int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids)
666 const char **menu_items = v4l2_ctrl_get_menu(qmenu->id);
669 if (menu_items == NULL || ids == NULL)
671 while (*ids != V4L2_CTRL_MENU_IDS_END) {
672 if (*ids++ == qmenu->index) {
673 snprintf(qmenu->name, sizeof(qmenu->name),
674 menu_items[qmenu->index]);
680 EXPORT_SYMBOL(v4l2_ctrl_query_menu_valid_items);
682 /* ctrl_classes points to an array of u32 pointers, the last element is
683 a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
684 Each array must be sorted low to high and belong to the same control
685 class. The array of u32 pointer must also be sorted, from low class IDs
688 This function returns the first ID that follows after the given ID.
689 When no more controls are available 0 is returned. */
690 u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
692 u32 ctrl_class = V4L2_CTRL_ID2CLASS(id);
695 if (ctrl_classes == NULL)
698 /* if no query is desired, then check if the ID is part of ctrl_classes */
699 if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0) {
701 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) != ctrl_class)
703 if (*ctrl_classes == NULL)
705 pctrl = *ctrl_classes;
706 /* find control ID */
707 while (*pctrl && *pctrl != id) pctrl++;
708 return *pctrl ? id : 0;
710 id &= V4L2_CTRL_ID_MASK;
711 id++; /* select next control */
712 /* find first class that matches (or is greater than) the class of
714 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) < ctrl_class)
716 /* no more classes */
717 if (*ctrl_classes == NULL)
719 pctrl = *ctrl_classes;
720 /* find first ctrl within the class that is >= ID */
721 while (*pctrl && *pctrl < id) pctrl++;
724 /* we are at the end of the controls of the current class. */
725 /* continue with next class if available */
727 if (*ctrl_classes == NULL)
729 return **ctrl_classes;
731 EXPORT_SYMBOL(v4l2_ctrl_next);
733 int v4l2_chip_match_host(u32 match_type, u32 match_chip)
735 switch (match_type) {
736 case V4L2_CHIP_MATCH_HOST:
737 return match_chip == 0;
742 EXPORT_SYMBOL(v4l2_chip_match_host);
744 #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
745 int v4l2_chip_match_i2c_client(struct i2c_client *c, u32 match_type, u32 match_chip)
747 switch (match_type) {
748 case V4L2_CHIP_MATCH_I2C_DRIVER:
749 return (c != NULL && c->driver != NULL && c->driver->id == match_chip);
750 case V4L2_CHIP_MATCH_I2C_ADDR:
751 return (c != NULL && c->addr == match_chip);
756 EXPORT_SYMBOL(v4l2_chip_match_i2c_client);
758 int v4l2_chip_ident_i2c_client(struct i2c_client *c, struct v4l2_chip_ident *chip,
759 u32 ident, u32 revision)
761 if (!v4l2_chip_match_i2c_client(c, chip->match_type, chip->match_chip))
763 if (chip->ident == V4L2_IDENT_NONE) {
765 chip->revision = revision;
768 chip->ident = V4L2_IDENT_AMBIGUOUS;
773 EXPORT_SYMBOL(v4l2_chip_ident_i2c_client);
775 /* ----------------------------------------------------------------- */
777 /* Helper function for I2C legacy drivers */
779 int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver,
781 int (*probe)(struct i2c_client *, const struct i2c_device_id *))
783 struct i2c_client *client;
786 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
790 client->addr = address;
791 client->adapter = adapter;
792 client->driver = driver;
793 strlcpy(client->name, name, sizeof(client->name));
795 err = probe(client, NULL);
797 i2c_attach_client(client);
801 return err != -ENOMEM ? 0 : err;
803 EXPORT_SYMBOL(v4l2_i2c_attach);