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-device.h>
62 #include <media/v4l2-chip-ident.h>
64 #include <linux/videodev2.h>
66 MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
67 MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers");
68 MODULE_LICENSE("GPL");
72 * V 4 L 2 D R I V E R H E L P E R A P I
77 * Video Standard Operations (contributed by Michael Schimek)
81 /* ----------------------------------------------------------------- */
82 /* priority handling */
84 #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND || \
85 val == V4L2_PRIORITY_INTERACTIVE || \
86 val == V4L2_PRIORITY_RECORD)
88 int v4l2_prio_init(struct v4l2_prio_state *global)
90 memset(global,0,sizeof(*global));
93 EXPORT_SYMBOL(v4l2_prio_init);
95 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
96 enum v4l2_priority new)
98 if (!V4L2_PRIO_VALID(new))
103 atomic_inc(&global->prios[new]);
104 if (V4L2_PRIO_VALID(*local))
105 atomic_dec(&global->prios[*local]);
109 EXPORT_SYMBOL(v4l2_prio_change);
111 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
113 return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
115 EXPORT_SYMBOL(v4l2_prio_open);
117 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
119 if (V4L2_PRIO_VALID(*local))
120 atomic_dec(&global->prios[*local]);
123 EXPORT_SYMBOL(v4l2_prio_close);
125 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
127 if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
128 return V4L2_PRIORITY_RECORD;
129 if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
130 return V4L2_PRIORITY_INTERACTIVE;
131 if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
132 return V4L2_PRIORITY_BACKGROUND;
133 return V4L2_PRIORITY_UNSET;
135 EXPORT_SYMBOL(v4l2_prio_max);
137 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
139 if (*local < v4l2_prio_max(global))
143 EXPORT_SYMBOL(v4l2_prio_check);
145 /* ----------------------------------------------------------------- */
147 /* Helper functions for control handling */
149 /* Check for correctness of the ctrl's value based on the data from
150 struct v4l2_queryctrl and the available menu items. Note that
151 menu_items may be NULL, in that case it is ignored. */
152 int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
153 const char **menu_items)
155 if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED)
157 if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED)
159 if (qctrl->type == V4L2_CTRL_TYPE_BUTTON ||
160 qctrl->type == V4L2_CTRL_TYPE_INTEGER64 ||
161 qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
163 if (ctrl->value < qctrl->minimum || ctrl->value > qctrl->maximum)
165 if (qctrl->type == V4L2_CTRL_TYPE_MENU && menu_items != NULL) {
166 if (menu_items[ctrl->value] == NULL ||
167 menu_items[ctrl->value][0] == '\0')
172 EXPORT_SYMBOL(v4l2_ctrl_check);
174 /* Returns NULL or a character pointer array containing the menu for
175 the given control ID. The pointer array ends with a NULL pointer.
176 An empty string signifies a menu entry that is invalid. This allows
177 drivers to disable certain options if it is not supported. */
178 const char **v4l2_ctrl_get_menu(u32 id)
180 static const char *mpeg_audio_sampling_freq[] = {
186 static const char *mpeg_audio_encoding[] = {
189 "MPEG-1/2 Layer III",
194 static const char *mpeg_audio_l1_bitrate[] = {
211 static const char *mpeg_audio_l2_bitrate[] = {
228 static const char *mpeg_audio_l3_bitrate[] = {
245 static const char *mpeg_audio_ac3_bitrate[] = {
267 static const char *mpeg_audio_mode[] = {
274 static const char *mpeg_audio_mode_extension[] = {
281 static const char *mpeg_audio_emphasis[] = {
287 static const char *mpeg_audio_crc[] = {
292 static const char *mpeg_video_encoding[] = {
298 static const char *mpeg_video_aspect[] = {
305 static const char *mpeg_video_bitrate_mode[] = {
310 static const char *mpeg_stream_type[] = {
311 "MPEG-2 Program Stream",
312 "MPEG-2 Transport Stream",
313 "MPEG-1 System Stream",
314 "MPEG-2 DVD-compatible Stream",
315 "MPEG-1 VCD-compatible Stream",
316 "MPEG-2 SVCD-compatible Stream",
319 static const char *mpeg_stream_vbi_fmt[] = {
321 "Private packet, IVTV format",
324 static const char *camera_power_line_frequency[] = {
330 static const char *camera_exposure_auto[] = {
333 "Shutter Priority Mode",
334 "Aperture Priority Mode",
337 static const char *colorfx[] = {
345 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
346 return mpeg_audio_sampling_freq;
347 case V4L2_CID_MPEG_AUDIO_ENCODING:
348 return mpeg_audio_encoding;
349 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
350 return mpeg_audio_l1_bitrate;
351 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
352 return mpeg_audio_l2_bitrate;
353 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
354 return mpeg_audio_l3_bitrate;
355 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
356 return mpeg_audio_ac3_bitrate;
357 case V4L2_CID_MPEG_AUDIO_MODE:
358 return mpeg_audio_mode;
359 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
360 return mpeg_audio_mode_extension;
361 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
362 return mpeg_audio_emphasis;
363 case V4L2_CID_MPEG_AUDIO_CRC:
364 return mpeg_audio_crc;
365 case V4L2_CID_MPEG_VIDEO_ENCODING:
366 return mpeg_video_encoding;
367 case V4L2_CID_MPEG_VIDEO_ASPECT:
368 return mpeg_video_aspect;
369 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
370 return mpeg_video_bitrate_mode;
371 case V4L2_CID_MPEG_STREAM_TYPE:
372 return mpeg_stream_type;
373 case V4L2_CID_MPEG_STREAM_VBI_FMT:
374 return mpeg_stream_vbi_fmt;
375 case V4L2_CID_POWER_LINE_FREQUENCY:
376 return camera_power_line_frequency;
377 case V4L2_CID_EXPOSURE_AUTO:
378 return camera_exposure_auto;
379 case V4L2_CID_COLORFX:
385 EXPORT_SYMBOL(v4l2_ctrl_get_menu);
387 /* Return the control name. */
388 const char *v4l2_ctrl_get_name(u32 id)
392 case V4L2_CID_USER_CLASS: return "User Controls";
393 case V4L2_CID_AUDIO_VOLUME: return "Volume";
394 case V4L2_CID_AUDIO_MUTE: return "Mute";
395 case V4L2_CID_AUDIO_BALANCE: return "Balance";
396 case V4L2_CID_AUDIO_BASS: return "Bass";
397 case V4L2_CID_AUDIO_TREBLE: return "Treble";
398 case V4L2_CID_AUDIO_LOUDNESS: return "Loudness";
399 case V4L2_CID_BRIGHTNESS: return "Brightness";
400 case V4L2_CID_CONTRAST: return "Contrast";
401 case V4L2_CID_SATURATION: return "Saturation";
402 case V4L2_CID_HUE: return "Hue";
403 case V4L2_CID_BLACK_LEVEL: return "Black Level";
404 case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic";
405 case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance";
406 case V4L2_CID_RED_BALANCE: return "Red Balance";
407 case V4L2_CID_BLUE_BALANCE: return "Blue Balance";
408 case V4L2_CID_GAMMA: return "Gamma";
409 case V4L2_CID_EXPOSURE: return "Exposure";
410 case V4L2_CID_AUTOGAIN: return "Gain, Automatic";
411 case V4L2_CID_GAIN: return "Gain";
412 case V4L2_CID_HFLIP: return "Horizontal Flip";
413 case V4L2_CID_VFLIP: return "Vertical Flip";
414 case V4L2_CID_HCENTER: return "Horizontal Center";
415 case V4L2_CID_VCENTER: return "Vertical Center";
416 case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency";
417 case V4L2_CID_HUE_AUTO: return "Hue, Automatic";
418 case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature";
419 case V4L2_CID_SHARPNESS: return "Sharpness";
420 case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation";
421 case V4L2_CID_CHROMA_AGC: return "Chroma AGC";
422 case V4L2_CID_COLOR_KILLER: return "Color Killer";
423 case V4L2_CID_COLORFX: return "Color Effects";
426 case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls";
427 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
428 case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding";
429 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate";
430 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate";
431 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate";
432 case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate";
433 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate";
434 case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode";
435 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
436 case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis";
437 case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC";
438 case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute";
439 case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding";
440 case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect";
441 case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames";
442 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size";
443 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure";
444 case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown";
445 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode";
446 case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate";
447 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate";
448 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
449 case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute";
450 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV";
451 case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type";
452 case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID";
453 case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID";
454 case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID";
455 case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID";
456 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
457 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
458 case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format";
460 /* CAMERA controls */
461 case V4L2_CID_CAMERA_CLASS: return "Camera Controls";
462 case V4L2_CID_EXPOSURE_AUTO: return "Auto Exposure";
463 case V4L2_CID_EXPOSURE_ABSOLUTE: return "Exposure Time, Absolute";
464 case V4L2_CID_EXPOSURE_AUTO_PRIORITY: return "Exposure, Dynamic Framerate";
465 case V4L2_CID_PAN_RELATIVE: return "Pan, Relative";
466 case V4L2_CID_TILT_RELATIVE: return "Tilt, Relative";
467 case V4L2_CID_PAN_RESET: return "Pan, Reset";
468 case V4L2_CID_TILT_RESET: return "Tilt, Reset";
469 case V4L2_CID_PAN_ABSOLUTE: return "Pan, Absolute";
470 case V4L2_CID_TILT_ABSOLUTE: return "Tilt, Absolute";
471 case V4L2_CID_FOCUS_ABSOLUTE: return "Focus, Absolute";
472 case V4L2_CID_FOCUS_RELATIVE: return "Focus, Relative";
473 case V4L2_CID_FOCUS_AUTO: return "Focus, Automatic";
474 case V4L2_CID_ZOOM_ABSOLUTE: return "Zoom, Absolute";
475 case V4L2_CID_ZOOM_RELATIVE: return "Zoom, Relative";
476 case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous";
477 case V4L2_CID_PRIVACY: return "Privacy";
483 EXPORT_SYMBOL(v4l2_ctrl_get_name);
485 /* Fill in a struct v4l2_queryctrl */
486 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
488 const char *name = v4l2_ctrl_get_name(qctrl->id);
495 case V4L2_CID_AUDIO_MUTE:
496 case V4L2_CID_AUDIO_LOUDNESS:
497 case V4L2_CID_AUTO_WHITE_BALANCE:
498 case V4L2_CID_AUTOGAIN:
501 case V4L2_CID_HUE_AUTO:
502 case V4L2_CID_MPEG_AUDIO_MUTE:
503 case V4L2_CID_MPEG_VIDEO_MUTE:
504 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
505 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
506 case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
507 case V4L2_CID_PRIVACY:
508 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
512 case V4L2_CID_POWER_LINE_FREQUENCY:
513 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
514 case V4L2_CID_MPEG_AUDIO_ENCODING:
515 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
516 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
517 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
518 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
519 case V4L2_CID_MPEG_AUDIO_MODE:
520 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
521 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
522 case V4L2_CID_MPEG_AUDIO_CRC:
523 case V4L2_CID_MPEG_VIDEO_ENCODING:
524 case V4L2_CID_MPEG_VIDEO_ASPECT:
525 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
526 case V4L2_CID_MPEG_STREAM_TYPE:
527 case V4L2_CID_MPEG_STREAM_VBI_FMT:
528 case V4L2_CID_EXPOSURE_AUTO:
529 case V4L2_CID_COLORFX:
530 qctrl->type = V4L2_CTRL_TYPE_MENU;
533 case V4L2_CID_USER_CLASS:
534 case V4L2_CID_CAMERA_CLASS:
535 case V4L2_CID_MPEG_CLASS:
536 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
537 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
538 min = max = step = def = 0;
541 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
545 case V4L2_CID_MPEG_AUDIO_ENCODING:
546 case V4L2_CID_MPEG_AUDIO_MODE:
547 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
548 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
549 case V4L2_CID_MPEG_STREAM_TYPE:
550 qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
552 case V4L2_CID_AUDIO_VOLUME:
553 case V4L2_CID_AUDIO_BALANCE:
554 case V4L2_CID_AUDIO_BASS:
555 case V4L2_CID_AUDIO_TREBLE:
556 case V4L2_CID_BRIGHTNESS:
557 case V4L2_CID_CONTRAST:
558 case V4L2_CID_SATURATION:
560 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
563 qctrl->minimum = min;
564 qctrl->maximum = max;
566 qctrl->default_value = def;
567 qctrl->reserved[0] = qctrl->reserved[1] = 0;
568 strlcpy(qctrl->name, name, sizeof(qctrl->name));
571 EXPORT_SYMBOL(v4l2_ctrl_query_fill);
573 /* Fill in a struct v4l2_queryctrl with standard values based on
575 int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
579 case V4L2_CID_USER_CLASS:
580 case V4L2_CID_MPEG_CLASS:
581 return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0);
582 case V4L2_CID_AUDIO_VOLUME:
583 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 58880);
584 case V4L2_CID_AUDIO_MUTE:
585 case V4L2_CID_AUDIO_LOUDNESS:
586 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
587 case V4L2_CID_AUDIO_BALANCE:
588 case V4L2_CID_AUDIO_BASS:
589 case V4L2_CID_AUDIO_TREBLE:
590 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 32768);
591 case V4L2_CID_BRIGHTNESS:
592 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
593 case V4L2_CID_CONTRAST:
594 case V4L2_CID_SATURATION:
595 return v4l2_ctrl_query_fill(qctrl, 0, 127, 1, 64);
597 return v4l2_ctrl_query_fill(qctrl, -128, 127, 1, 0);
598 case V4L2_CID_COLORFX:
599 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
602 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
603 return v4l2_ctrl_query_fill(qctrl,
604 V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100,
605 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 1,
606 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
607 case V4L2_CID_MPEG_AUDIO_ENCODING:
608 return v4l2_ctrl_query_fill(qctrl,
609 V4L2_MPEG_AUDIO_ENCODING_LAYER_1,
610 V4L2_MPEG_AUDIO_ENCODING_AC3, 1,
611 V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
612 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
613 return v4l2_ctrl_query_fill(qctrl,
614 V4L2_MPEG_AUDIO_L1_BITRATE_32K,
615 V4L2_MPEG_AUDIO_L1_BITRATE_448K, 1,
616 V4L2_MPEG_AUDIO_L1_BITRATE_256K);
617 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
618 return v4l2_ctrl_query_fill(qctrl,
619 V4L2_MPEG_AUDIO_L2_BITRATE_32K,
620 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
621 V4L2_MPEG_AUDIO_L2_BITRATE_224K);
622 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
623 return v4l2_ctrl_query_fill(qctrl,
624 V4L2_MPEG_AUDIO_L3_BITRATE_32K,
625 V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1,
626 V4L2_MPEG_AUDIO_L3_BITRATE_192K);
627 case V4L2_CID_MPEG_AUDIO_AAC_BITRATE:
628 return v4l2_ctrl_query_fill(qctrl, 0, 6400, 1, 3200000);
629 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
630 return v4l2_ctrl_query_fill(qctrl,
631 V4L2_MPEG_AUDIO_AC3_BITRATE_32K,
632 V4L2_MPEG_AUDIO_AC3_BITRATE_640K, 1,
633 V4L2_MPEG_AUDIO_AC3_BITRATE_384K);
634 case V4L2_CID_MPEG_AUDIO_MODE:
635 return v4l2_ctrl_query_fill(qctrl,
636 V4L2_MPEG_AUDIO_MODE_STEREO,
637 V4L2_MPEG_AUDIO_MODE_MONO, 1,
638 V4L2_MPEG_AUDIO_MODE_STEREO);
639 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
640 return v4l2_ctrl_query_fill(qctrl,
641 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4,
642 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 1,
643 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4);
644 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
645 return v4l2_ctrl_query_fill(qctrl,
646 V4L2_MPEG_AUDIO_EMPHASIS_NONE,
647 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 1,
648 V4L2_MPEG_AUDIO_EMPHASIS_NONE);
649 case V4L2_CID_MPEG_AUDIO_CRC:
650 return v4l2_ctrl_query_fill(qctrl,
651 V4L2_MPEG_AUDIO_CRC_NONE,
652 V4L2_MPEG_AUDIO_CRC_CRC16, 1,
653 V4L2_MPEG_AUDIO_CRC_NONE);
654 case V4L2_CID_MPEG_AUDIO_MUTE:
655 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
656 case V4L2_CID_MPEG_VIDEO_ENCODING:
657 return v4l2_ctrl_query_fill(qctrl,
658 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
659 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
660 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
661 case V4L2_CID_MPEG_VIDEO_ASPECT:
662 return v4l2_ctrl_query_fill(qctrl,
663 V4L2_MPEG_VIDEO_ASPECT_1x1,
664 V4L2_MPEG_VIDEO_ASPECT_221x100, 1,
665 V4L2_MPEG_VIDEO_ASPECT_4x3);
666 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
667 return v4l2_ctrl_query_fill(qctrl, 0, 33, 1, 2);
668 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
669 return v4l2_ctrl_query_fill(qctrl, 1, 34, 1, 12);
670 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
671 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1);
672 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
673 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
674 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
675 return v4l2_ctrl_query_fill(qctrl,
676 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
677 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
678 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
679 case V4L2_CID_MPEG_VIDEO_BITRATE:
680 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
681 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
682 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
683 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
684 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
685 case V4L2_CID_MPEG_VIDEO_MUTE:
686 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
687 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: /* Init YUV (really YCbCr) to black */
688 return v4l2_ctrl_query_fill(qctrl, 0, 0xffffff, 1, 0x008080);
689 case V4L2_CID_MPEG_STREAM_TYPE:
690 return v4l2_ctrl_query_fill(qctrl,
691 V4L2_MPEG_STREAM_TYPE_MPEG2_PS,
692 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, 1,
693 V4L2_MPEG_STREAM_TYPE_MPEG2_PS);
694 case V4L2_CID_MPEG_STREAM_PID_PMT:
695 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16);
696 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
697 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260);
698 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
699 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256);
700 case V4L2_CID_MPEG_STREAM_PID_PCR:
701 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259);
702 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO:
703 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
704 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO:
705 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
706 case V4L2_CID_MPEG_STREAM_VBI_FMT:
707 return v4l2_ctrl_query_fill(qctrl,
708 V4L2_MPEG_STREAM_VBI_FMT_NONE,
709 V4L2_MPEG_STREAM_VBI_FMT_IVTV, 1,
710 V4L2_MPEG_STREAM_VBI_FMT_NONE);
715 EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);
717 /* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
718 the menu. The qctrl pointer may be NULL, in which case it is ignored.
719 If menu_items is NULL, then the menu items are retrieved using
720 v4l2_ctrl_get_menu. */
721 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
722 const char **menu_items)
727 if (menu_items == NULL)
728 menu_items = v4l2_ctrl_get_menu(qmenu->id);
729 if (menu_items == NULL ||
730 (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum)))
732 for (i = 0; i < qmenu->index && menu_items[i]; i++) ;
733 if (menu_items[i] == NULL || menu_items[i][0] == '\0')
735 strlcpy(qmenu->name, menu_items[qmenu->index], sizeof(qmenu->name));
738 EXPORT_SYMBOL(v4l2_ctrl_query_menu);
740 /* Fill in a struct v4l2_querymenu based on the specified array of valid
741 menu items (terminated by V4L2_CTRL_MENU_IDS_END).
742 Use this if there are 'holes' in the list of valid menu items. */
743 int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids)
745 const char **menu_items = v4l2_ctrl_get_menu(qmenu->id);
748 if (menu_items == NULL || ids == NULL)
750 while (*ids != V4L2_CTRL_MENU_IDS_END) {
751 if (*ids++ == qmenu->index) {
752 strlcpy(qmenu->name, menu_items[qmenu->index],
753 sizeof(qmenu->name));
759 EXPORT_SYMBOL(v4l2_ctrl_query_menu_valid_items);
761 /* ctrl_classes points to an array of u32 pointers, the last element is
762 a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
763 Each array must be sorted low to high and belong to the same control
764 class. The array of u32 pointers must also be sorted, from low class IDs
767 This function returns the first ID that follows after the given ID.
768 When no more controls are available 0 is returned. */
769 u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
771 u32 ctrl_class = V4L2_CTRL_ID2CLASS(id);
774 if (ctrl_classes == NULL)
777 /* if no query is desired, then check if the ID is part of ctrl_classes */
778 if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0) {
780 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) != ctrl_class)
782 if (*ctrl_classes == NULL)
784 pctrl = *ctrl_classes;
785 /* find control ID */
786 while (*pctrl && *pctrl != id) pctrl++;
787 return *pctrl ? id : 0;
789 id &= V4L2_CTRL_ID_MASK;
790 id++; /* select next control */
791 /* find first class that matches (or is greater than) the class of
793 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) < ctrl_class)
795 /* no more classes */
796 if (*ctrl_classes == NULL)
798 pctrl = *ctrl_classes;
799 /* find first ctrl within the class that is >= ID */
800 while (*pctrl && *pctrl < id) pctrl++;
803 /* we are at the end of the controls of the current class. */
804 /* continue with next class if available */
806 if (*ctrl_classes == NULL)
808 return **ctrl_classes;
810 EXPORT_SYMBOL(v4l2_ctrl_next);
812 int v4l2_chip_match_host(const struct v4l2_dbg_match *match)
814 switch (match->type) {
815 case V4L2_CHIP_MATCH_HOST:
816 return match->addr == 0;
821 EXPORT_SYMBOL(v4l2_chip_match_host);
823 #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
824 int v4l2_chip_match_i2c_client(struct i2c_client *c, const struct v4l2_dbg_match *match)
828 if (c == NULL || match == NULL)
831 switch (match->type) {
832 case V4L2_CHIP_MATCH_I2C_DRIVER:
833 if (c->driver == NULL || c->driver->driver.name == NULL)
835 len = strlen(c->driver->driver.name);
836 /* legacy drivers have a ' suffix, don't try to match that */
837 if (len && c->driver->driver.name[len - 1] == '\'')
839 return len && !strncmp(c->driver->driver.name, match->name, len);
840 case V4L2_CHIP_MATCH_I2C_ADDR:
841 return c->addr == match->addr;
846 EXPORT_SYMBOL(v4l2_chip_match_i2c_client);
848 int v4l2_chip_ident_i2c_client(struct i2c_client *c, struct v4l2_dbg_chip_ident *chip,
849 u32 ident, u32 revision)
851 if (!v4l2_chip_match_i2c_client(c, &chip->match))
853 if (chip->ident == V4L2_IDENT_NONE) {
855 chip->revision = revision;
858 chip->ident = V4L2_IDENT_AMBIGUOUS;
863 EXPORT_SYMBOL(v4l2_chip_ident_i2c_client);
865 /* ----------------------------------------------------------------- */
867 /* Helper function for I2C legacy drivers */
869 int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver,
871 int (*probe)(struct i2c_client *, const struct i2c_device_id *))
873 struct i2c_client *client;
876 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
880 client->addr = address;
881 client->adapter = adapter;
882 client->driver = driver;
883 strlcpy(client->name, name, sizeof(client->name));
885 err = probe(client, NULL);
887 i2c_attach_client(client);
891 return err != -ENOMEM ? 0 : err;
893 EXPORT_SYMBOL(v4l2_i2c_attach);
895 void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
896 const struct v4l2_subdev_ops *ops)
898 v4l2_subdev_init(sd, ops);
899 /* the owner is the same as the i2c_client's driver owner */
900 sd->owner = client->driver->driver.owner;
901 /* i2c_client and v4l2_subdev point to one another */
902 v4l2_set_subdevdata(sd, client);
903 i2c_set_clientdata(client, sd);
904 /* initialize name */
905 snprintf(sd->name, sizeof(sd->name), "%s %d-%04x",
906 client->driver->driver.name, i2c_adapter_id(client->adapter),
909 EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init);
913 /* Load an i2c sub-device. It assumes that i2c_get_adapdata(adapter)
914 returns the v4l2_device and that i2c_get_clientdata(client)
915 returns the v4l2_subdev. */
916 struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter,
917 const char *module_name, const char *client_type, u8 addr)
919 struct v4l2_device *dev = i2c_get_adapdata(adapter);
920 struct v4l2_subdev *sd = NULL;
921 struct i2c_client *client;
922 struct i2c_board_info info;
927 request_module(module_name);
929 /* Setup the i2c board info with the device type and
930 the device address. */
931 memset(&info, 0, sizeof(info));
932 strlcpy(info.type, client_type, sizeof(info.type));
935 /* Create the i2c client */
936 client = i2c_new_device(adapter, &info);
937 /* Note: it is possible in the future that
938 c->driver is NULL if the driver is still being loaded.
939 We need better support from the kernel so that we
940 can easily wait for the load to finish. */
941 if (client == NULL || client->driver == NULL)
944 /* Lock the module so we can safely get the v4l2_subdev pointer */
945 if (!try_module_get(client->driver->driver.owner))
947 sd = i2c_get_clientdata(client);
949 /* Register with the v4l2_device which increases the module's
950 use count as well. */
951 if (v4l2_device_register_subdev(dev, sd))
953 /* Decrease the module use count to match the first try_module_get. */
954 module_put(client->driver->driver.owner);
958 EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev);
960 /* Probe and load an i2c sub-device. It assumes that i2c_get_adapdata(adapter)
961 returns the v4l2_device and that i2c_get_clientdata(client)
962 returns the v4l2_subdev. */
963 struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter,
964 const char *module_name, const char *client_type,
965 const unsigned short *addrs)
967 struct v4l2_device *dev = i2c_get_adapdata(adapter);
968 struct v4l2_subdev *sd = NULL;
969 struct i2c_client *client = NULL;
970 struct i2c_board_info info;
975 request_module(module_name);
977 /* Setup the i2c board info with the device type and
978 the device address. */
979 memset(&info, 0, sizeof(info));
980 strlcpy(info.type, client_type, sizeof(info.type));
982 /* Probe and create the i2c client */
983 client = i2c_new_probed_device(adapter, &info, addrs);
984 /* Note: it is possible in the future that
985 c->driver is NULL if the driver is still being loaded.
986 We need better support from the kernel so that we
987 can easily wait for the load to finish. */
988 if (client == NULL || client->driver == NULL)
991 /* Lock the module so we can safely get the v4l2_subdev pointer */
992 if (!try_module_get(client->driver->driver.owner))
994 sd = i2c_get_clientdata(client);
996 /* Register with the v4l2_device which increases the module's
997 use count as well. */
998 if (v4l2_device_register_subdev(dev, sd))
1000 /* Decrease the module use count to match the first try_module_get. */
1001 module_put(client->driver->driver.owner);
1004 EXPORT_SYMBOL_GPL(v4l2_i2c_new_probed_subdev);
1006 /* Return a list of I2C tuner addresses to probe. Use only if the tuner
1007 addresses are unknown. */
1008 const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)
1010 static const unsigned short radio_addrs[] = {
1011 #if defined(CONFIG_MEDIA_TUNER_TEA5761) || defined(CONFIG_MEDIA_TUNER_TEA5761_MODULE)
1017 static const unsigned short demod_addrs[] = {
1018 0x42, 0x43, 0x4a, 0x4b,
1021 static const unsigned short tv_addrs[] = {
1022 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */
1023 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
1024 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
1035 case ADDRS_TV_WITH_DEMOD:
1036 return tv_addrs + 4;
1040 EXPORT_SYMBOL_GPL(v4l2_i2c_tuner_addrs);