1 // SPDX-License-Identifier: GPL-2.0-or-later
3 V4L2 controls framework implementation.
5 Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
9 #define pr_fmt(fmt) "v4l2-ctrls: " fmt
11 #include <linux/ctype.h>
12 #include <linux/export.h>
14 #include <linux/slab.h>
15 #include <media/v4l2-ctrls.h>
16 #include <media/v4l2-dev.h>
17 #include <media/v4l2-device.h>
18 #include <media/v4l2-event.h>
19 #include <media/v4l2-fwnode.h>
20 #include <media/v4l2-ioctl.h>
22 #define dprintk(vdev, fmt, arg...) do { \
23 if (!WARN_ON(!(vdev)) && ((vdev)->dev_debug & V4L2_DEV_DEBUG_CTRL)) \
24 printk(KERN_DEBUG pr_fmt("%s: %s: " fmt), \
25 __func__, video_device_node_name(vdev), ##arg); \
28 #define has_op(master, op) \
29 (master->ops && master->ops->op)
30 #define call_op(master, op) \
31 (has_op(master, op) ? master->ops->op(master) : 0)
33 static const union v4l2_ctrl_ptr ptr_null;
35 /* Internal temporary helper struct, one for each v4l2_ext_control */
36 struct v4l2_ctrl_helper {
37 /* Pointer to the control reference of the master control */
38 struct v4l2_ctrl_ref *mref;
39 /* The control ref corresponding to the v4l2_ext_control ID field. */
40 struct v4l2_ctrl_ref *ref;
41 /* v4l2_ext_control index of the next control belonging to the
42 same cluster, or 0 if there isn't any. */
46 /* Small helper function to determine if the autocluster is set to manual
48 static bool is_cur_manual(const struct v4l2_ctrl *master)
50 return master->is_auto && master->cur.val == master->manual_mode_value;
53 /* Same as above, but this checks the against the new value instead of the
55 static bool is_new_manual(const struct v4l2_ctrl *master)
57 return master->is_auto && master->val == master->manual_mode_value;
60 /* Returns NULL or a character pointer array containing the menu for
61 the given control ID. The pointer array ends with a NULL pointer.
62 An empty string signifies a menu entry that is invalid. This allows
63 drivers to disable certain options if it is not supported. */
64 const char * const *v4l2_ctrl_get_menu(u32 id)
66 static const char * const mpeg_audio_sampling_freq[] = {
72 static const char * const mpeg_audio_encoding[] = {
80 static const char * const mpeg_audio_l1_bitrate[] = {
97 static const char * const mpeg_audio_l2_bitrate[] = {
114 static const char * const mpeg_audio_l3_bitrate[] = {
131 static const char * const mpeg_audio_ac3_bitrate[] = {
153 static const char * const mpeg_audio_mode[] = {
160 static const char * const mpeg_audio_mode_extension[] = {
167 static const char * const mpeg_audio_emphasis[] = {
173 static const char * const mpeg_audio_crc[] = {
178 static const char * const mpeg_audio_dec_playback[] = {
187 static const char * const mpeg_video_encoding[] = {
193 static const char * const mpeg_video_aspect[] = {
200 static const char * const mpeg_video_bitrate_mode[] = {
205 static const char * const mpeg_stream_type[] = {
206 "MPEG-2 Program Stream",
207 "MPEG-2 Transport Stream",
208 "MPEG-1 System Stream",
209 "MPEG-2 DVD-compatible Stream",
210 "MPEG-1 VCD-compatible Stream",
211 "MPEG-2 SVCD-compatible Stream",
214 static const char * const mpeg_stream_vbi_fmt[] = {
216 "Private Packet, IVTV Format",
219 static const char * const camera_power_line_frequency[] = {
226 static const char * const camera_exposure_auto[] = {
229 "Shutter Priority Mode",
230 "Aperture Priority Mode",
233 static const char * const camera_exposure_metering[] = {
240 static const char * const camera_auto_focus_range[] = {
247 static const char * const colorfx[] = {
266 static const char * const auto_n_preset_white_balance[] = {
279 static const char * const camera_iso_sensitivity_auto[] = {
284 static const char * const scene_mode[] = {
301 static const char * const tune_emphasis[] = {
307 static const char * const header_mode[] = {
309 "Joined With 1st Frame",
312 static const char * const multi_slice[] = {
318 static const char * const entropy_mode[] = {
323 static const char * const mpeg_h264_level[] = {
346 static const char * const h264_loop_filter[] = {
349 "Disabled at Slice Boundary",
352 static const char * const h264_profile[] = {
354 "Constrained Baseline",
360 "High 444 Predictive",
367 "Scalable High Intra",
373 static const char * const vui_sar_idc[] = {
394 static const char * const h264_fp_arrangement_type[] = {
403 static const char * const h264_fmo_map_type[] = {
404 "Interleaved Slices",
406 "Foreground with Leftover",
413 static const char * const h264_decode_mode[] = {
418 static const char * const h264_start_code[] = {
420 "Annex B Start Code",
423 static const char * const mpeg_mpeg2_level[] = {
430 static const char * const mpeg2_profile[] = {
434 "Spatially Scalable",
438 static const char * const mpeg_mpeg4_level[] = {
449 static const char * const mpeg4_profile[] = {
454 "Advanced Coding Efficiency",
458 static const char * const vpx_golden_frame_sel[] = {
459 "Use Previous Frame",
460 "Use Previous Specific Frame",
463 static const char * const vp8_profile[] = {
470 static const char * const vp9_profile[] = {
478 static const char * const flash_led_mode[] = {
484 static const char * const flash_strobe_source[] = {
490 static const char * const jpeg_chroma_subsampling[] = {
499 static const char * const dv_tx_mode[] = {
504 static const char * const dv_rgb_range[] = {
506 "RGB Limited Range (16-235)",
507 "RGB Full Range (0-255)",
510 static const char * const dv_it_content_type[] = {
518 static const char * const detect_md_mode[] = {
526 static const char * const hevc_profile[] = {
528 "Main Still Picture",
532 static const char * const hevc_level[] = {
548 static const char * const hevc_hierarchial_coding_type[] = {
553 static const char * const hevc_refresh_type[] = {
559 static const char * const hevc_size_of_length_field[] = {
566 static const char * const hevc_tier[] = {
571 static const char * const hevc_loop_filter_mode[] = {
574 "Disabled at slice boundary",
577 static const char * const hevc_decode_mode[] = {
582 static const char * const hevc_start_code[] = {
584 "Annex B Start Code",
587 static const char * const camera_orientation[] = {
595 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
596 return mpeg_audio_sampling_freq;
597 case V4L2_CID_MPEG_AUDIO_ENCODING:
598 return mpeg_audio_encoding;
599 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
600 return mpeg_audio_l1_bitrate;
601 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
602 return mpeg_audio_l2_bitrate;
603 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
604 return mpeg_audio_l3_bitrate;
605 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
606 return mpeg_audio_ac3_bitrate;
607 case V4L2_CID_MPEG_AUDIO_MODE:
608 return mpeg_audio_mode;
609 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
610 return mpeg_audio_mode_extension;
611 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
612 return mpeg_audio_emphasis;
613 case V4L2_CID_MPEG_AUDIO_CRC:
614 return mpeg_audio_crc;
615 case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK:
616 case V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK:
617 return mpeg_audio_dec_playback;
618 case V4L2_CID_MPEG_VIDEO_ENCODING:
619 return mpeg_video_encoding;
620 case V4L2_CID_MPEG_VIDEO_ASPECT:
621 return mpeg_video_aspect;
622 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
623 return mpeg_video_bitrate_mode;
624 case V4L2_CID_MPEG_STREAM_TYPE:
625 return mpeg_stream_type;
626 case V4L2_CID_MPEG_STREAM_VBI_FMT:
627 return mpeg_stream_vbi_fmt;
628 case V4L2_CID_POWER_LINE_FREQUENCY:
629 return camera_power_line_frequency;
630 case V4L2_CID_EXPOSURE_AUTO:
631 return camera_exposure_auto;
632 case V4L2_CID_EXPOSURE_METERING:
633 return camera_exposure_metering;
634 case V4L2_CID_AUTO_FOCUS_RANGE:
635 return camera_auto_focus_range;
636 case V4L2_CID_COLORFX:
638 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
639 return auto_n_preset_white_balance;
640 case V4L2_CID_ISO_SENSITIVITY_AUTO:
641 return camera_iso_sensitivity_auto;
642 case V4L2_CID_SCENE_MODE:
644 case V4L2_CID_TUNE_PREEMPHASIS:
645 return tune_emphasis;
646 case V4L2_CID_TUNE_DEEMPHASIS:
647 return tune_emphasis;
648 case V4L2_CID_FLASH_LED_MODE:
649 return flash_led_mode;
650 case V4L2_CID_FLASH_STROBE_SOURCE:
651 return flash_strobe_source;
652 case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
654 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
656 case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
658 case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
659 return mpeg_h264_level;
660 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
661 return h264_loop_filter;
662 case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
664 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC:
666 case V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE:
667 return h264_fp_arrangement_type;
668 case V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE:
669 return h264_fmo_map_type;
670 case V4L2_CID_MPEG_VIDEO_H264_DECODE_MODE:
671 return h264_decode_mode;
672 case V4L2_CID_MPEG_VIDEO_H264_START_CODE:
673 return h264_start_code;
674 case V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL:
675 return mpeg_mpeg2_level;
676 case V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE:
677 return mpeg2_profile;
678 case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
679 return mpeg_mpeg4_level;
680 case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
681 return mpeg4_profile;
682 case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL:
683 return vpx_golden_frame_sel;
684 case V4L2_CID_MPEG_VIDEO_VP8_PROFILE:
686 case V4L2_CID_MPEG_VIDEO_VP9_PROFILE:
688 case V4L2_CID_JPEG_CHROMA_SUBSAMPLING:
689 return jpeg_chroma_subsampling;
690 case V4L2_CID_DV_TX_MODE:
692 case V4L2_CID_DV_TX_RGB_RANGE:
693 case V4L2_CID_DV_RX_RGB_RANGE:
695 case V4L2_CID_DV_TX_IT_CONTENT_TYPE:
696 case V4L2_CID_DV_RX_IT_CONTENT_TYPE:
697 return dv_it_content_type;
698 case V4L2_CID_DETECT_MD_MODE:
699 return detect_md_mode;
700 case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE:
702 case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL:
704 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE:
705 return hevc_hierarchial_coding_type;
706 case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE:
707 return hevc_refresh_type;
708 case V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD:
709 return hevc_size_of_length_field;
710 case V4L2_CID_MPEG_VIDEO_HEVC_TIER:
712 case V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE:
713 return hevc_loop_filter_mode;
714 case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE:
715 return hevc_decode_mode;
716 case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE:
717 return hevc_start_code;
718 case V4L2_CID_CAMERA_ORIENTATION:
719 return camera_orientation;
724 EXPORT_SYMBOL(v4l2_ctrl_get_menu);
726 #define __v4l2_qmenu_int_len(arr, len) ({ *(len) = ARRAY_SIZE(arr); arr; })
728 * Returns NULL or an s64 type array containing the menu for given
729 * control ID. The total number of the menu items is returned in @len.
731 const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len)
733 static const s64 qmenu_int_vpx_num_partitions[] = {
737 static const s64 qmenu_int_vpx_num_ref_frames[] = {
742 case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS:
743 return __v4l2_qmenu_int_len(qmenu_int_vpx_num_partitions, len);
744 case V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES:
745 return __v4l2_qmenu_int_len(qmenu_int_vpx_num_ref_frames, len);
751 EXPORT_SYMBOL(v4l2_ctrl_get_int_menu);
753 /* Return the control name. */
754 const char *v4l2_ctrl_get_name(u32 id)
758 /* Keep the order of the 'case's the same as in v4l2-controls.h! */
759 case V4L2_CID_USER_CLASS: return "User Controls";
760 case V4L2_CID_BRIGHTNESS: return "Brightness";
761 case V4L2_CID_CONTRAST: return "Contrast";
762 case V4L2_CID_SATURATION: return "Saturation";
763 case V4L2_CID_HUE: return "Hue";
764 case V4L2_CID_AUDIO_VOLUME: return "Volume";
765 case V4L2_CID_AUDIO_BALANCE: return "Balance";
766 case V4L2_CID_AUDIO_BASS: return "Bass";
767 case V4L2_CID_AUDIO_TREBLE: return "Treble";
768 case V4L2_CID_AUDIO_MUTE: return "Mute";
769 case V4L2_CID_AUDIO_LOUDNESS: return "Loudness";
770 case V4L2_CID_BLACK_LEVEL: return "Black Level";
771 case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic";
772 case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance";
773 case V4L2_CID_RED_BALANCE: return "Red Balance";
774 case V4L2_CID_BLUE_BALANCE: return "Blue Balance";
775 case V4L2_CID_GAMMA: return "Gamma";
776 case V4L2_CID_EXPOSURE: return "Exposure";
777 case V4L2_CID_AUTOGAIN: return "Gain, Automatic";
778 case V4L2_CID_GAIN: return "Gain";
779 case V4L2_CID_HFLIP: return "Horizontal Flip";
780 case V4L2_CID_VFLIP: return "Vertical Flip";
781 case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency";
782 case V4L2_CID_HUE_AUTO: return "Hue, Automatic";
783 case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature";
784 case V4L2_CID_SHARPNESS: return "Sharpness";
785 case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation";
786 case V4L2_CID_CHROMA_AGC: return "Chroma AGC";
787 case V4L2_CID_COLOR_KILLER: return "Color Killer";
788 case V4L2_CID_COLORFX: return "Color Effects";
789 case V4L2_CID_AUTOBRIGHTNESS: return "Brightness, Automatic";
790 case V4L2_CID_BAND_STOP_FILTER: return "Band-Stop Filter";
791 case V4L2_CID_ROTATE: return "Rotate";
792 case V4L2_CID_BG_COLOR: return "Background Color";
793 case V4L2_CID_CHROMA_GAIN: return "Chroma Gain";
794 case V4L2_CID_ILLUMINATORS_1: return "Illuminator 1";
795 case V4L2_CID_ILLUMINATORS_2: return "Illuminator 2";
796 case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE: return "Min Number of Capture Buffers";
797 case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT: return "Min Number of Output Buffers";
798 case V4L2_CID_ALPHA_COMPONENT: return "Alpha Component";
799 case V4L2_CID_COLORFX_CBCR: return "Color Effects, CbCr";
802 /* The MPEG controls are applicable to all codec controls
803 * and the 'MPEG' part of the define is historical */
804 /* Keep the order of the 'case's the same as in videodev2.h! */
805 case V4L2_CID_MPEG_CLASS: return "Codec Controls";
806 case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type";
807 case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID";
808 case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID";
809 case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID";
810 case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID";
811 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
812 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
813 case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format";
814 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
815 case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding";
816 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate";
817 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate";
818 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate";
819 case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode";
820 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
821 case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis";
822 case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC";
823 case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute";
824 case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate";
825 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate";
826 case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK: return "Audio Playback";
827 case V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK: return "Audio Multilingual Playback";
828 case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding";
829 case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect";
830 case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames";
831 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size";
832 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure";
833 case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown";
834 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode";
835 case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate";
836 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate";
837 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
838 case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute";
839 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV";
840 case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE: return "Decoder Slice Interface";
841 case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER: return "MPEG4 Loop Filter Enable";
842 case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB: return "Number of Intra Refresh MBs";
843 case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE: return "Frame Level Rate Control Enable";
844 case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE: return "H264 MB Level Rate Control";
845 case V4L2_CID_MPEG_VIDEO_HEADER_MODE: return "Sequence Header Mode";
846 case V4L2_CID_MPEG_VIDEO_MAX_REF_PIC: return "Max Number of Reference Pics";
847 case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP: return "H263 I-Frame QP Value";
848 case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP: return "H263 P-Frame QP Value";
849 case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP: return "H263 B-Frame QP Value";
850 case V4L2_CID_MPEG_VIDEO_H263_MIN_QP: return "H263 Minimum QP Value";
851 case V4L2_CID_MPEG_VIDEO_H263_MAX_QP: return "H263 Maximum QP Value";
852 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: return "H264 I-Frame QP Value";
853 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: return "H264 P-Frame QP Value";
854 case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP: return "H264 B-Frame QP Value";
855 case V4L2_CID_MPEG_VIDEO_H264_MAX_QP: return "H264 Maximum QP Value";
856 case V4L2_CID_MPEG_VIDEO_H264_MIN_QP: return "H264 Minimum QP Value";
857 case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM: return "H264 8x8 Transform Enable";
858 case V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE: return "H264 CPB Buffer Size";
859 case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: return "H264 Entropy Mode";
860 case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD: return "H264 I-Frame Period";
861 case V4L2_CID_MPEG_VIDEO_H264_LEVEL: return "H264 Level";
862 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA: return "H264 Loop Filter Alpha Offset";
863 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA: return "H264 Loop Filter Beta Offset";
864 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: return "H264 Loop Filter Mode";
865 case V4L2_CID_MPEG_VIDEO_H264_PROFILE: return "H264 Profile";
866 case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT: return "Vertical Size of SAR";
867 case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH: return "Horizontal Size of SAR";
868 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE: return "Aspect Ratio VUI Enable";
869 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC: return "VUI Aspect Ratio IDC";
870 case V4L2_CID_MPEG_VIDEO_H264_SEI_FRAME_PACKING: return "H264 Enable Frame Packing SEI";
871 case V4L2_CID_MPEG_VIDEO_H264_SEI_FP_CURRENT_FRAME_0: return "H264 Set Curr. Frame as Frame0";
872 case V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE: return "H264 FP Arrangement Type";
873 case V4L2_CID_MPEG_VIDEO_H264_FMO: return "H264 Flexible MB Ordering";
874 case V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE: return "H264 Map Type for FMO";
875 case V4L2_CID_MPEG_VIDEO_H264_FMO_SLICE_GROUP: return "H264 FMO Number of Slice Groups";
876 case V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_DIRECTION: return "H264 FMO Direction of Change";
877 case V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_RATE: return "H264 FMO Size of 1st Slice Grp";
878 case V4L2_CID_MPEG_VIDEO_H264_FMO_RUN_LENGTH: return "H264 FMO No. of Consecutive MBs";
879 case V4L2_CID_MPEG_VIDEO_H264_ASO: return "H264 Arbitrary Slice Ordering";
880 case V4L2_CID_MPEG_VIDEO_H264_ASO_SLICE_ORDER: return "H264 ASO Slice Order";
881 case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING: return "Enable H264 Hierarchical Coding";
882 case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE: return "H264 Hierarchical Coding Type";
883 case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER:return "H264 Number of HC Layers";
884 case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER_QP:
885 return "H264 Set QP Value for HC Layers";
886 case V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION:
887 return "H264 Constrained Intra Pred";
888 case V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET: return "H264 Chroma QP Index Offset";
889 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QP: return "H264 I-Frame Minimum QP Value";
890 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QP: return "H264 I-Frame Maximum QP Value";
891 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QP: return "H264 P-Frame Minimum QP Value";
892 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QP: return "H264 P-Frame Maximum QP Value";
893 case V4L2_CID_MPEG_VIDEO_H264_SPS: return "H264 Sequence Parameter Set";
894 case V4L2_CID_MPEG_VIDEO_H264_PPS: return "H264 Picture Parameter Set";
895 case V4L2_CID_MPEG_VIDEO_H264_SCALING_MATRIX: return "H264 Scaling Matrix";
896 case V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAMS: return "H264 Slice Parameters";
897 case V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS: return "H264 Decode Parameters";
898 case V4L2_CID_MPEG_VIDEO_H264_DECODE_MODE: return "H264 Decode Mode";
899 case V4L2_CID_MPEG_VIDEO_H264_START_CODE: return "H264 Start Code";
900 case V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL: return "MPEG2 Level";
901 case V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE: return "MPEG2 Profile";
902 case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP: return "MPEG4 I-Frame QP Value";
903 case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP: return "MPEG4 P-Frame QP Value";
904 case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP: return "MPEG4 B-Frame QP Value";
905 case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP: return "MPEG4 Minimum QP Value";
906 case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP: return "MPEG4 Maximum QP Value";
907 case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL: return "MPEG4 Level";
908 case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE: return "MPEG4 Profile";
909 case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL: return "Quarter Pixel Search Enable";
910 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: return "Maximum Bytes in a Slice";
911 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: return "Number of MBs in a Slice";
912 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: return "Slice Partitioning Method";
913 case V4L2_CID_MPEG_VIDEO_VBV_SIZE: return "VBV Buffer Size";
914 case V4L2_CID_MPEG_VIDEO_DEC_PTS: return "Video Decoder PTS";
915 case V4L2_CID_MPEG_VIDEO_DEC_FRAME: return "Video Decoder Frame Count";
916 case V4L2_CID_MPEG_VIDEO_VBV_DELAY: return "Initial Delay for VBV Control";
917 case V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE: return "Horizontal MV Search Range";
918 case V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE: return "Vertical MV Search Range";
919 case V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER: return "Repeat Sequence Header";
920 case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: return "Force Key Frame";
921 case V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS: return "MPEG-2 Slice Parameters";
922 case V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION: return "MPEG-2 Quantization Matrices";
923 case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS: return "FWHT Stateless Parameters";
924 case V4L2_CID_FWHT_I_FRAME_QP: return "FWHT I-Frame QP Value";
925 case V4L2_CID_FWHT_P_FRAME_QP: return "FWHT P-Frame QP Value";
928 case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS: return "VPX Number of Partitions";
929 case V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4: return "VPX Intra Mode Decision Disable";
930 case V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES: return "VPX No. of Refs for P Frame";
931 case V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL: return "VPX Loop Filter Level Range";
932 case V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS: return "VPX Deblocking Effect Control";
933 case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD: return "VPX Golden Frame Refresh Period";
934 case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL: return "VPX Golden Frame Indicator";
935 case V4L2_CID_MPEG_VIDEO_VPX_MIN_QP: return "VPX Minimum QP Value";
936 case V4L2_CID_MPEG_VIDEO_VPX_MAX_QP: return "VPX Maximum QP Value";
937 case V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP: return "VPX I-Frame QP Value";
938 case V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP: return "VPX P-Frame QP Value";
939 case V4L2_CID_MPEG_VIDEO_VP8_PROFILE: return "VP8 Profile";
940 case V4L2_CID_MPEG_VIDEO_VP9_PROFILE: return "VP9 Profile";
941 case V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER: return "VP8 Frame Header";
944 case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP: return "HEVC I-Frame QP Value";
945 case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP: return "HEVC P-Frame QP Value";
946 case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP: return "HEVC B-Frame QP Value";
947 case V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP: return "HEVC Minimum QP Value";
948 case V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP: return "HEVC Maximum QP Value";
949 case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE: return "HEVC Profile";
950 case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL: return "HEVC Level";
951 case V4L2_CID_MPEG_VIDEO_HEVC_TIER: return "HEVC Tier";
952 case V4L2_CID_MPEG_VIDEO_HEVC_FRAME_RATE_RESOLUTION: return "HEVC Frame Rate Resolution";
953 case V4L2_CID_MPEG_VIDEO_HEVC_MAX_PARTITION_DEPTH: return "HEVC Maximum Coding Unit Depth";
954 case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE: return "HEVC Refresh Type";
955 case V4L2_CID_MPEG_VIDEO_HEVC_CONST_INTRA_PRED: return "HEVC Constant Intra Prediction";
956 case V4L2_CID_MPEG_VIDEO_HEVC_LOSSLESS_CU: return "HEVC Lossless Encoding";
957 case V4L2_CID_MPEG_VIDEO_HEVC_WAVEFRONT: return "HEVC Wavefront";
958 case V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE: return "HEVC Loop Filter";
959 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_QP: return "HEVC QP Values";
960 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE: return "HEVC Hierarchical Coding Type";
961 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER: return "HEVC Hierarchical Coding Layer";
962 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_QP: return "HEVC Hierarchical Layer 0 QP";
963 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_QP: return "HEVC Hierarchical Layer 1 QP";
964 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_QP: return "HEVC Hierarchical Layer 2 QP";
965 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_QP: return "HEVC Hierarchical Layer 3 QP";
966 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_QP: return "HEVC Hierarchical Layer 4 QP";
967 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_QP: return "HEVC Hierarchical Layer 5 QP";
968 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_QP: return "HEVC Hierarchical Layer 6 QP";
969 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR: return "HEVC Hierarchical Lay 0 BitRate";
970 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR: return "HEVC Hierarchical Lay 1 BitRate";
971 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR: return "HEVC Hierarchical Lay 2 BitRate";
972 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR: return "HEVC Hierarchical Lay 3 BitRate";
973 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR: return "HEVC Hierarchical Lay 4 BitRate";
974 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR: return "HEVC Hierarchical Lay 5 BitRate";
975 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR: return "HEVC Hierarchical Lay 6 BitRate";
976 case V4L2_CID_MPEG_VIDEO_HEVC_GENERAL_PB: return "HEVC General PB";
977 case V4L2_CID_MPEG_VIDEO_HEVC_TEMPORAL_ID: return "HEVC Temporal ID";
978 case V4L2_CID_MPEG_VIDEO_HEVC_STRONG_SMOOTHING: return "HEVC Strong Intra Smoothing";
979 case V4L2_CID_MPEG_VIDEO_HEVC_INTRA_PU_SPLIT: return "HEVC Intra PU Split";
980 case V4L2_CID_MPEG_VIDEO_HEVC_TMV_PREDICTION: return "HEVC TMV Prediction";
981 case V4L2_CID_MPEG_VIDEO_HEVC_MAX_NUM_MERGE_MV_MINUS1: return "HEVC Max Num of Candidate MVs";
982 case V4L2_CID_MPEG_VIDEO_HEVC_WITHOUT_STARTCODE: return "HEVC ENC Without Startcode";
983 case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_PERIOD: return "HEVC Num of I-Frame b/w 2 IDR";
984 case V4L2_CID_MPEG_VIDEO_HEVC_LF_BETA_OFFSET_DIV2: return "HEVC Loop Filter Beta Offset";
985 case V4L2_CID_MPEG_VIDEO_HEVC_LF_TC_OFFSET_DIV2: return "HEVC Loop Filter TC Offset";
986 case V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD: return "HEVC Size of Length Field";
987 case V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES: return "Reference Frames for a P-Frame";
988 case V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR: return "Prepend SPS and PPS to IDR";
989 case V4L2_CID_MPEG_VIDEO_HEVC_SPS: return "HEVC Sequence Parameter Set";
990 case V4L2_CID_MPEG_VIDEO_HEVC_PPS: return "HEVC Picture Parameter Set";
991 case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS: return "HEVC Slice Parameters";
992 case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE: return "HEVC Decode Mode";
993 case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE: return "HEVC Start Code";
995 /* CAMERA controls */
996 /* Keep the order of the 'case's the same as in v4l2-controls.h! */
997 case V4L2_CID_CAMERA_CLASS: return "Camera Controls";
998 case V4L2_CID_EXPOSURE_AUTO: return "Auto Exposure";
999 case V4L2_CID_EXPOSURE_ABSOLUTE: return "Exposure Time, Absolute";
1000 case V4L2_CID_EXPOSURE_AUTO_PRIORITY: return "Exposure, Dynamic Framerate";
1001 case V4L2_CID_PAN_RELATIVE: return "Pan, Relative";
1002 case V4L2_CID_TILT_RELATIVE: return "Tilt, Relative";
1003 case V4L2_CID_PAN_RESET: return "Pan, Reset";
1004 case V4L2_CID_TILT_RESET: return "Tilt, Reset";
1005 case V4L2_CID_PAN_ABSOLUTE: return "Pan, Absolute";
1006 case V4L2_CID_TILT_ABSOLUTE: return "Tilt, Absolute";
1007 case V4L2_CID_FOCUS_ABSOLUTE: return "Focus, Absolute";
1008 case V4L2_CID_FOCUS_RELATIVE: return "Focus, Relative";
1009 case V4L2_CID_FOCUS_AUTO: return "Focus, Automatic Continuous";
1010 case V4L2_CID_ZOOM_ABSOLUTE: return "Zoom, Absolute";
1011 case V4L2_CID_ZOOM_RELATIVE: return "Zoom, Relative";
1012 case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous";
1013 case V4L2_CID_PRIVACY: return "Privacy";
1014 case V4L2_CID_IRIS_ABSOLUTE: return "Iris, Absolute";
1015 case V4L2_CID_IRIS_RELATIVE: return "Iris, Relative";
1016 case V4L2_CID_AUTO_EXPOSURE_BIAS: return "Auto Exposure, Bias";
1017 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE: return "White Balance, Auto & Preset";
1018 case V4L2_CID_WIDE_DYNAMIC_RANGE: return "Wide Dynamic Range";
1019 case V4L2_CID_IMAGE_STABILIZATION: return "Image Stabilization";
1020 case V4L2_CID_ISO_SENSITIVITY: return "ISO Sensitivity";
1021 case V4L2_CID_ISO_SENSITIVITY_AUTO: return "ISO Sensitivity, Auto";
1022 case V4L2_CID_EXPOSURE_METERING: return "Exposure, Metering Mode";
1023 case V4L2_CID_SCENE_MODE: return "Scene Mode";
1024 case V4L2_CID_3A_LOCK: return "3A Lock";
1025 case V4L2_CID_AUTO_FOCUS_START: return "Auto Focus, Start";
1026 case V4L2_CID_AUTO_FOCUS_STOP: return "Auto Focus, Stop";
1027 case V4L2_CID_AUTO_FOCUS_STATUS: return "Auto Focus, Status";
1028 case V4L2_CID_AUTO_FOCUS_RANGE: return "Auto Focus, Range";
1029 case V4L2_CID_PAN_SPEED: return "Pan, Speed";
1030 case V4L2_CID_TILT_SPEED: return "Tilt, Speed";
1031 case V4L2_CID_UNIT_CELL_SIZE: return "Unit Cell Size";
1032 case V4L2_CID_CAMERA_ORIENTATION: return "Camera Orientation";
1033 case V4L2_CID_CAMERA_SENSOR_ROTATION: return "Camera Sensor Rotation";
1035 /* FM Radio Modulator controls */
1036 /* Keep the order of the 'case's the same as in v4l2-controls.h! */
1037 case V4L2_CID_FM_TX_CLASS: return "FM Radio Modulator Controls";
1038 case V4L2_CID_RDS_TX_DEVIATION: return "RDS Signal Deviation";
1039 case V4L2_CID_RDS_TX_PI: return "RDS Program ID";
1040 case V4L2_CID_RDS_TX_PTY: return "RDS Program Type";
1041 case V4L2_CID_RDS_TX_PS_NAME: return "RDS PS Name";
1042 case V4L2_CID_RDS_TX_RADIO_TEXT: return "RDS Radio Text";
1043 case V4L2_CID_RDS_TX_MONO_STEREO: return "RDS Stereo";
1044 case V4L2_CID_RDS_TX_ARTIFICIAL_HEAD: return "RDS Artificial Head";
1045 case V4L2_CID_RDS_TX_COMPRESSED: return "RDS Compressed";
1046 case V4L2_CID_RDS_TX_DYNAMIC_PTY: return "RDS Dynamic PTY";
1047 case V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT: return "RDS Traffic Announcement";
1048 case V4L2_CID_RDS_TX_TRAFFIC_PROGRAM: return "RDS Traffic Program";
1049 case V4L2_CID_RDS_TX_MUSIC_SPEECH: return "RDS Music";
1050 case V4L2_CID_RDS_TX_ALT_FREQS_ENABLE: return "RDS Enable Alt Frequencies";
1051 case V4L2_CID_RDS_TX_ALT_FREQS: return "RDS Alternate Frequencies";
1052 case V4L2_CID_AUDIO_LIMITER_ENABLED: return "Audio Limiter Feature Enabled";
1053 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: return "Audio Limiter Release Time";
1054 case V4L2_CID_AUDIO_LIMITER_DEVIATION: return "Audio Limiter Deviation";
1055 case V4L2_CID_AUDIO_COMPRESSION_ENABLED: return "Audio Compression Enabled";
1056 case V4L2_CID_AUDIO_COMPRESSION_GAIN: return "Audio Compression Gain";
1057 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: return "Audio Compression Threshold";
1058 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: return "Audio Compression Attack Time";
1059 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: return "Audio Compression Release Time";
1060 case V4L2_CID_PILOT_TONE_ENABLED: return "Pilot Tone Feature Enabled";
1061 case V4L2_CID_PILOT_TONE_DEVIATION: return "Pilot Tone Deviation";
1062 case V4L2_CID_PILOT_TONE_FREQUENCY: return "Pilot Tone Frequency";
1063 case V4L2_CID_TUNE_PREEMPHASIS: return "Pre-Emphasis";
1064 case V4L2_CID_TUNE_POWER_LEVEL: return "Tune Power Level";
1065 case V4L2_CID_TUNE_ANTENNA_CAPACITOR: return "Tune Antenna Capacitor";
1067 /* Flash controls */
1068 /* Keep the order of the 'case's the same as in v4l2-controls.h! */
1069 case V4L2_CID_FLASH_CLASS: return "Flash Controls";
1070 case V4L2_CID_FLASH_LED_MODE: return "LED Mode";
1071 case V4L2_CID_FLASH_STROBE_SOURCE: return "Strobe Source";
1072 case V4L2_CID_FLASH_STROBE: return "Strobe";
1073 case V4L2_CID_FLASH_STROBE_STOP: return "Stop Strobe";
1074 case V4L2_CID_FLASH_STROBE_STATUS: return "Strobe Status";
1075 case V4L2_CID_FLASH_TIMEOUT: return "Strobe Timeout";
1076 case V4L2_CID_FLASH_INTENSITY: return "Intensity, Flash Mode";
1077 case V4L2_CID_FLASH_TORCH_INTENSITY: return "Intensity, Torch Mode";
1078 case V4L2_CID_FLASH_INDICATOR_INTENSITY: return "Intensity, Indicator";
1079 case V4L2_CID_FLASH_FAULT: return "Faults";
1080 case V4L2_CID_FLASH_CHARGE: return "Charge";
1081 case V4L2_CID_FLASH_READY: return "Ready to Strobe";
1083 /* JPEG encoder controls */
1084 /* Keep the order of the 'case's the same as in v4l2-controls.h! */
1085 case V4L2_CID_JPEG_CLASS: return "JPEG Compression Controls";
1086 case V4L2_CID_JPEG_CHROMA_SUBSAMPLING: return "Chroma Subsampling";
1087 case V4L2_CID_JPEG_RESTART_INTERVAL: return "Restart Interval";
1088 case V4L2_CID_JPEG_COMPRESSION_QUALITY: return "Compression Quality";
1089 case V4L2_CID_JPEG_ACTIVE_MARKER: return "Active Markers";
1091 /* Image source controls */
1092 /* Keep the order of the 'case's the same as in v4l2-controls.h! */
1093 case V4L2_CID_IMAGE_SOURCE_CLASS: return "Image Source Controls";
1094 case V4L2_CID_VBLANK: return "Vertical Blanking";
1095 case V4L2_CID_HBLANK: return "Horizontal Blanking";
1096 case V4L2_CID_ANALOGUE_GAIN: return "Analogue Gain";
1097 case V4L2_CID_TEST_PATTERN_RED: return "Red Pixel Value";
1098 case V4L2_CID_TEST_PATTERN_GREENR: return "Green (Red) Pixel Value";
1099 case V4L2_CID_TEST_PATTERN_BLUE: return "Blue Pixel Value";
1100 case V4L2_CID_TEST_PATTERN_GREENB: return "Green (Blue) Pixel Value";
1102 /* Image processing controls */
1103 /* Keep the order of the 'case's the same as in v4l2-controls.h! */
1104 case V4L2_CID_IMAGE_PROC_CLASS: return "Image Processing Controls";
1105 case V4L2_CID_LINK_FREQ: return "Link Frequency";
1106 case V4L2_CID_PIXEL_RATE: return "Pixel Rate";
1107 case V4L2_CID_TEST_PATTERN: return "Test Pattern";
1108 case V4L2_CID_DEINTERLACING_MODE: return "Deinterlacing Mode";
1109 case V4L2_CID_DIGITAL_GAIN: return "Digital Gain";
1112 /* Keep the order of the 'case's the same as in v4l2-controls.h! */
1113 case V4L2_CID_DV_CLASS: return "Digital Video Controls";
1114 case V4L2_CID_DV_TX_HOTPLUG: return "Hotplug Present";
1115 case V4L2_CID_DV_TX_RXSENSE: return "RxSense Present";
1116 case V4L2_CID_DV_TX_EDID_PRESENT: return "EDID Present";
1117 case V4L2_CID_DV_TX_MODE: return "Transmit Mode";
1118 case V4L2_CID_DV_TX_RGB_RANGE: return "Tx RGB Quantization Range";
1119 case V4L2_CID_DV_TX_IT_CONTENT_TYPE: return "Tx IT Content Type";
1120 case V4L2_CID_DV_RX_POWER_PRESENT: return "Power Present";
1121 case V4L2_CID_DV_RX_RGB_RANGE: return "Rx RGB Quantization Range";
1122 case V4L2_CID_DV_RX_IT_CONTENT_TYPE: return "Rx IT Content Type";
1124 case V4L2_CID_FM_RX_CLASS: return "FM Radio Receiver Controls";
1125 case V4L2_CID_TUNE_DEEMPHASIS: return "De-Emphasis";
1126 case V4L2_CID_RDS_RECEPTION: return "RDS Reception";
1127 case V4L2_CID_RF_TUNER_CLASS: return "RF Tuner Controls";
1128 case V4L2_CID_RF_TUNER_RF_GAIN: return "RF Gain";
1129 case V4L2_CID_RF_TUNER_LNA_GAIN_AUTO: return "LNA Gain, Auto";
1130 case V4L2_CID_RF_TUNER_LNA_GAIN: return "LNA Gain";
1131 case V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO: return "Mixer Gain, Auto";
1132 case V4L2_CID_RF_TUNER_MIXER_GAIN: return "Mixer Gain";
1133 case V4L2_CID_RF_TUNER_IF_GAIN_AUTO: return "IF Gain, Auto";
1134 case V4L2_CID_RF_TUNER_IF_GAIN: return "IF Gain";
1135 case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO: return "Bandwidth, Auto";
1136 case V4L2_CID_RF_TUNER_BANDWIDTH: return "Bandwidth";
1137 case V4L2_CID_RF_TUNER_PLL_LOCK: return "PLL Lock";
1138 case V4L2_CID_RDS_RX_PTY: return "RDS Program Type";
1139 case V4L2_CID_RDS_RX_PS_NAME: return "RDS PS Name";
1140 case V4L2_CID_RDS_RX_RADIO_TEXT: return "RDS Radio Text";
1141 case V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT: return "RDS Traffic Announcement";
1142 case V4L2_CID_RDS_RX_TRAFFIC_PROGRAM: return "RDS Traffic Program";
1143 case V4L2_CID_RDS_RX_MUSIC_SPEECH: return "RDS Music";
1145 /* Detection controls */
1146 /* Keep the order of the 'case's the same as in v4l2-controls.h! */
1147 case V4L2_CID_DETECT_CLASS: return "Detection Controls";
1148 case V4L2_CID_DETECT_MD_MODE: return "Motion Detection Mode";
1149 case V4L2_CID_DETECT_MD_GLOBAL_THRESHOLD: return "MD Global Threshold";
1150 case V4L2_CID_DETECT_MD_THRESHOLD_GRID: return "MD Threshold Grid";
1151 case V4L2_CID_DETECT_MD_REGION_GRID: return "MD Region Grid";
1156 EXPORT_SYMBOL(v4l2_ctrl_get_name);
1158 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
1159 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags)
1161 *name = v4l2_ctrl_get_name(id);
1165 case V4L2_CID_AUDIO_MUTE:
1166 case V4L2_CID_AUDIO_LOUDNESS:
1167 case V4L2_CID_AUTO_WHITE_BALANCE:
1168 case V4L2_CID_AUTOGAIN:
1169 case V4L2_CID_HFLIP:
1170 case V4L2_CID_VFLIP:
1171 case V4L2_CID_HUE_AUTO:
1172 case V4L2_CID_CHROMA_AGC:
1173 case V4L2_CID_COLOR_KILLER:
1174 case V4L2_CID_AUTOBRIGHTNESS:
1175 case V4L2_CID_MPEG_AUDIO_MUTE:
1176 case V4L2_CID_MPEG_VIDEO_MUTE:
1177 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
1178 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
1179 case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
1180 case V4L2_CID_FOCUS_AUTO:
1181 case V4L2_CID_PRIVACY:
1182 case V4L2_CID_AUDIO_LIMITER_ENABLED:
1183 case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
1184 case V4L2_CID_PILOT_TONE_ENABLED:
1185 case V4L2_CID_ILLUMINATORS_1:
1186 case V4L2_CID_ILLUMINATORS_2:
1187 case V4L2_CID_FLASH_STROBE_STATUS:
1188 case V4L2_CID_FLASH_CHARGE:
1189 case V4L2_CID_FLASH_READY:
1190 case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:
1191 case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE:
1192 case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:
1193 case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE:
1194 case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM:
1195 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE:
1196 case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL:
1197 case V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER:
1198 case V4L2_CID_WIDE_DYNAMIC_RANGE:
1199 case V4L2_CID_IMAGE_STABILIZATION:
1200 case V4L2_CID_RDS_RECEPTION:
1201 case V4L2_CID_RF_TUNER_LNA_GAIN_AUTO:
1202 case V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO:
1203 case V4L2_CID_RF_TUNER_IF_GAIN_AUTO:
1204 case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
1205 case V4L2_CID_RF_TUNER_PLL_LOCK:
1206 case V4L2_CID_RDS_TX_MONO_STEREO:
1207 case V4L2_CID_RDS_TX_ARTIFICIAL_HEAD:
1208 case V4L2_CID_RDS_TX_COMPRESSED:
1209 case V4L2_CID_RDS_TX_DYNAMIC_PTY:
1210 case V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT:
1211 case V4L2_CID_RDS_TX_TRAFFIC_PROGRAM:
1212 case V4L2_CID_RDS_TX_MUSIC_SPEECH:
1213 case V4L2_CID_RDS_TX_ALT_FREQS_ENABLE:
1214 case V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT:
1215 case V4L2_CID_RDS_RX_TRAFFIC_PROGRAM:
1216 case V4L2_CID_RDS_RX_MUSIC_SPEECH:
1217 *type = V4L2_CTRL_TYPE_BOOLEAN;
1221 case V4L2_CID_ROTATE:
1222 *type = V4L2_CTRL_TYPE_INTEGER;
1223 *flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
1225 case V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE:
1226 case V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE:
1227 *type = V4L2_CTRL_TYPE_INTEGER;
1229 case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME:
1230 case V4L2_CID_PAN_RESET:
1231 case V4L2_CID_TILT_RESET:
1232 case V4L2_CID_FLASH_STROBE:
1233 case V4L2_CID_FLASH_STROBE_STOP:
1234 case V4L2_CID_AUTO_FOCUS_START:
1235 case V4L2_CID_AUTO_FOCUS_STOP:
1236 case V4L2_CID_DO_WHITE_BALANCE:
1237 *type = V4L2_CTRL_TYPE_BUTTON;
1238 *flags |= V4L2_CTRL_FLAG_WRITE_ONLY |
1239 V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
1240 *min = *max = *step = *def = 0;
1242 case V4L2_CID_POWER_LINE_FREQUENCY:
1243 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1244 case V4L2_CID_MPEG_AUDIO_ENCODING:
1245 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
1246 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
1247 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
1248 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
1249 case V4L2_CID_MPEG_AUDIO_MODE:
1250 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
1251 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
1252 case V4L2_CID_MPEG_AUDIO_CRC:
1253 case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK:
1254 case V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK:
1255 case V4L2_CID_MPEG_VIDEO_ENCODING:
1256 case V4L2_CID_MPEG_VIDEO_ASPECT:
1257 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1258 case V4L2_CID_MPEG_STREAM_TYPE:
1259 case V4L2_CID_MPEG_STREAM_VBI_FMT:
1260 case V4L2_CID_EXPOSURE_AUTO:
1261 case V4L2_CID_AUTO_FOCUS_RANGE:
1262 case V4L2_CID_COLORFX:
1263 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
1264 case V4L2_CID_TUNE_PREEMPHASIS:
1265 case V4L2_CID_FLASH_LED_MODE:
1266 case V4L2_CID_FLASH_STROBE_SOURCE:
1267 case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
1268 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
1269 case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
1270 case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
1271 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
1272 case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
1273 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC:
1274 case V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE:
1275 case V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE:
1276 case V4L2_CID_MPEG_VIDEO_H264_DECODE_MODE:
1277 case V4L2_CID_MPEG_VIDEO_H264_START_CODE:
1278 case V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL:
1279 case V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE:
1280 case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
1281 case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
1282 case V4L2_CID_JPEG_CHROMA_SUBSAMPLING:
1283 case V4L2_CID_ISO_SENSITIVITY_AUTO:
1284 case V4L2_CID_EXPOSURE_METERING:
1285 case V4L2_CID_SCENE_MODE:
1286 case V4L2_CID_DV_TX_MODE:
1287 case V4L2_CID_DV_TX_RGB_RANGE:
1288 case V4L2_CID_DV_TX_IT_CONTENT_TYPE:
1289 case V4L2_CID_DV_RX_RGB_RANGE:
1290 case V4L2_CID_DV_RX_IT_CONTENT_TYPE:
1291 case V4L2_CID_TEST_PATTERN:
1292 case V4L2_CID_DEINTERLACING_MODE:
1293 case V4L2_CID_TUNE_DEEMPHASIS:
1294 case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL:
1295 case V4L2_CID_MPEG_VIDEO_VP8_PROFILE:
1296 case V4L2_CID_MPEG_VIDEO_VP9_PROFILE:
1297 case V4L2_CID_DETECT_MD_MODE:
1298 case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE:
1299 case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL:
1300 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE:
1301 case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE:
1302 case V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD:
1303 case V4L2_CID_MPEG_VIDEO_HEVC_TIER:
1304 case V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE:
1305 case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE:
1306 case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE:
1307 case V4L2_CID_CAMERA_ORIENTATION:
1308 *type = V4L2_CTRL_TYPE_MENU;
1310 case V4L2_CID_LINK_FREQ:
1311 *type = V4L2_CTRL_TYPE_INTEGER_MENU;
1313 case V4L2_CID_RDS_TX_PS_NAME:
1314 case V4L2_CID_RDS_TX_RADIO_TEXT:
1315 case V4L2_CID_RDS_RX_PS_NAME:
1316 case V4L2_CID_RDS_RX_RADIO_TEXT:
1317 *type = V4L2_CTRL_TYPE_STRING;
1319 case V4L2_CID_ISO_SENSITIVITY:
1320 case V4L2_CID_AUTO_EXPOSURE_BIAS:
1321 case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS:
1322 case V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES:
1323 *type = V4L2_CTRL_TYPE_INTEGER_MENU;
1325 case V4L2_CID_USER_CLASS:
1326 case V4L2_CID_CAMERA_CLASS:
1327 case V4L2_CID_MPEG_CLASS:
1328 case V4L2_CID_FM_TX_CLASS:
1329 case V4L2_CID_FLASH_CLASS:
1330 case V4L2_CID_JPEG_CLASS:
1331 case V4L2_CID_IMAGE_SOURCE_CLASS:
1332 case V4L2_CID_IMAGE_PROC_CLASS:
1333 case V4L2_CID_DV_CLASS:
1334 case V4L2_CID_FM_RX_CLASS:
1335 case V4L2_CID_RF_TUNER_CLASS:
1336 case V4L2_CID_DETECT_CLASS:
1337 *type = V4L2_CTRL_TYPE_CTRL_CLASS;
1338 /* You can neither read not write these */
1339 *flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
1340 *min = *max = *step = *def = 0;
1342 case V4L2_CID_BG_COLOR:
1343 *type = V4L2_CTRL_TYPE_INTEGER;
1346 /* Max is calculated as RGB888 that is 2^24 */
1349 case V4L2_CID_FLASH_FAULT:
1350 case V4L2_CID_JPEG_ACTIVE_MARKER:
1351 case V4L2_CID_3A_LOCK:
1352 case V4L2_CID_AUTO_FOCUS_STATUS:
1353 case V4L2_CID_DV_TX_HOTPLUG:
1354 case V4L2_CID_DV_TX_RXSENSE:
1355 case V4L2_CID_DV_TX_EDID_PRESENT:
1356 case V4L2_CID_DV_RX_POWER_PRESENT:
1357 *type = V4L2_CTRL_TYPE_BITMASK;
1359 case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
1360 case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
1361 *type = V4L2_CTRL_TYPE_INTEGER;
1362 *flags |= V4L2_CTRL_FLAG_READ_ONLY;
1364 case V4L2_CID_MPEG_VIDEO_DEC_PTS:
1365 *type = V4L2_CTRL_TYPE_INTEGER64;
1366 *flags |= V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY;
1368 *max = 0x1ffffffffLL;
1371 case V4L2_CID_MPEG_VIDEO_DEC_FRAME:
1372 *type = V4L2_CTRL_TYPE_INTEGER64;
1373 *flags |= V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY;
1375 *max = 0x7fffffffffffffffLL;
1378 case V4L2_CID_PIXEL_RATE:
1379 *type = V4L2_CTRL_TYPE_INTEGER64;
1380 *flags |= V4L2_CTRL_FLAG_READ_ONLY;
1382 case V4L2_CID_DETECT_MD_REGION_GRID:
1383 *type = V4L2_CTRL_TYPE_U8;
1385 case V4L2_CID_DETECT_MD_THRESHOLD_GRID:
1386 *type = V4L2_CTRL_TYPE_U16;
1388 case V4L2_CID_RDS_TX_ALT_FREQS:
1389 *type = V4L2_CTRL_TYPE_U32;
1391 case V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS:
1392 *type = V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS;
1394 case V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION:
1395 *type = V4L2_CTRL_TYPE_MPEG2_QUANTIZATION;
1397 case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS:
1398 *type = V4L2_CTRL_TYPE_FWHT_PARAMS;
1400 case V4L2_CID_MPEG_VIDEO_H264_SPS:
1401 *type = V4L2_CTRL_TYPE_H264_SPS;
1403 case V4L2_CID_MPEG_VIDEO_H264_PPS:
1404 *type = V4L2_CTRL_TYPE_H264_PPS;
1406 case V4L2_CID_MPEG_VIDEO_H264_SCALING_MATRIX:
1407 *type = V4L2_CTRL_TYPE_H264_SCALING_MATRIX;
1409 case V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAMS:
1410 *type = V4L2_CTRL_TYPE_H264_SLICE_PARAMS;
1412 case V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS:
1413 *type = V4L2_CTRL_TYPE_H264_DECODE_PARAMS;
1415 case V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER:
1416 *type = V4L2_CTRL_TYPE_VP8_FRAME_HEADER;
1418 case V4L2_CID_MPEG_VIDEO_HEVC_SPS:
1419 *type = V4L2_CTRL_TYPE_HEVC_SPS;
1421 case V4L2_CID_MPEG_VIDEO_HEVC_PPS:
1422 *type = V4L2_CTRL_TYPE_HEVC_PPS;
1424 case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS:
1425 *type = V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS;
1427 case V4L2_CID_UNIT_CELL_SIZE:
1428 *type = V4L2_CTRL_TYPE_AREA;
1429 *flags |= V4L2_CTRL_FLAG_READ_ONLY;
1432 *type = V4L2_CTRL_TYPE_INTEGER;
1436 case V4L2_CID_MPEG_AUDIO_ENCODING:
1437 case V4L2_CID_MPEG_AUDIO_MODE:
1438 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1439 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
1440 case V4L2_CID_MPEG_STREAM_TYPE:
1441 *flags |= V4L2_CTRL_FLAG_UPDATE;
1443 case V4L2_CID_AUDIO_VOLUME:
1444 case V4L2_CID_AUDIO_BALANCE:
1445 case V4L2_CID_AUDIO_BASS:
1446 case V4L2_CID_AUDIO_TREBLE:
1447 case V4L2_CID_BRIGHTNESS:
1448 case V4L2_CID_CONTRAST:
1449 case V4L2_CID_SATURATION:
1451 case V4L2_CID_RED_BALANCE:
1452 case V4L2_CID_BLUE_BALANCE:
1453 case V4L2_CID_GAMMA:
1454 case V4L2_CID_SHARPNESS:
1455 case V4L2_CID_CHROMA_GAIN:
1456 case V4L2_CID_RDS_TX_DEVIATION:
1457 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
1458 case V4L2_CID_AUDIO_LIMITER_DEVIATION:
1459 case V4L2_CID_AUDIO_COMPRESSION_GAIN:
1460 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
1461 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
1462 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
1463 case V4L2_CID_PILOT_TONE_DEVIATION:
1464 case V4L2_CID_PILOT_TONE_FREQUENCY:
1465 case V4L2_CID_TUNE_POWER_LEVEL:
1466 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
1467 case V4L2_CID_RF_TUNER_RF_GAIN:
1468 case V4L2_CID_RF_TUNER_LNA_GAIN:
1469 case V4L2_CID_RF_TUNER_MIXER_GAIN:
1470 case V4L2_CID_RF_TUNER_IF_GAIN:
1471 case V4L2_CID_RF_TUNER_BANDWIDTH:
1472 case V4L2_CID_DETECT_MD_GLOBAL_THRESHOLD:
1473 *flags |= V4L2_CTRL_FLAG_SLIDER;
1475 case V4L2_CID_PAN_RELATIVE:
1476 case V4L2_CID_TILT_RELATIVE:
1477 case V4L2_CID_FOCUS_RELATIVE:
1478 case V4L2_CID_IRIS_RELATIVE:
1479 case V4L2_CID_ZOOM_RELATIVE:
1480 *flags |= V4L2_CTRL_FLAG_WRITE_ONLY |
1481 V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
1483 case V4L2_CID_FLASH_STROBE_STATUS:
1484 case V4L2_CID_AUTO_FOCUS_STATUS:
1485 case V4L2_CID_FLASH_READY:
1486 case V4L2_CID_DV_TX_HOTPLUG:
1487 case V4L2_CID_DV_TX_RXSENSE:
1488 case V4L2_CID_DV_TX_EDID_PRESENT:
1489 case V4L2_CID_DV_RX_POWER_PRESENT:
1490 case V4L2_CID_DV_RX_IT_CONTENT_TYPE:
1491 case V4L2_CID_RDS_RX_PTY:
1492 case V4L2_CID_RDS_RX_PS_NAME:
1493 case V4L2_CID_RDS_RX_RADIO_TEXT:
1494 case V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT:
1495 case V4L2_CID_RDS_RX_TRAFFIC_PROGRAM:
1496 case V4L2_CID_RDS_RX_MUSIC_SPEECH:
1497 case V4L2_CID_CAMERA_ORIENTATION:
1498 case V4L2_CID_CAMERA_SENSOR_ROTATION:
1499 *flags |= V4L2_CTRL_FLAG_READ_ONLY;
1501 case V4L2_CID_RF_TUNER_PLL_LOCK:
1502 *flags |= V4L2_CTRL_FLAG_VOLATILE;
1506 EXPORT_SYMBOL(v4l2_ctrl_fill);
1508 static u32 user_flags(const struct v4l2_ctrl *ctrl)
1510 u32 flags = ctrl->flags;
1513 flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD;
1518 static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl, u32 changes)
1520 memset(ev, 0, sizeof(*ev));
1521 ev->type = V4L2_EVENT_CTRL;
1523 ev->u.ctrl.changes = changes;
1524 ev->u.ctrl.type = ctrl->type;
1525 ev->u.ctrl.flags = user_flags(ctrl);
1527 ev->u.ctrl.value64 = 0;
1529 ev->u.ctrl.value64 = *ctrl->p_cur.p_s64;
1530 ev->u.ctrl.minimum = ctrl->minimum;
1531 ev->u.ctrl.maximum = ctrl->maximum;
1532 if (ctrl->type == V4L2_CTRL_TYPE_MENU
1533 || ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU)
1534 ev->u.ctrl.step = 1;
1536 ev->u.ctrl.step = ctrl->step;
1537 ev->u.ctrl.default_value = ctrl->default_value;
1540 static void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes)
1542 struct v4l2_event ev;
1543 struct v4l2_subscribed_event *sev;
1545 if (list_empty(&ctrl->ev_subs))
1547 fill_event(&ev, ctrl, changes);
1549 list_for_each_entry(sev, &ctrl->ev_subs, node)
1550 if (sev->fh != fh ||
1551 (sev->flags & V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK))
1552 v4l2_event_queue_fh(sev->fh, &ev);
1555 static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
1556 union v4l2_ctrl_ptr ptr1,
1557 union v4l2_ctrl_ptr ptr2)
1559 switch (ctrl->type) {
1560 case V4L2_CTRL_TYPE_BUTTON:
1562 case V4L2_CTRL_TYPE_STRING:
1563 idx *= ctrl->elem_size;
1564 /* strings are always 0-terminated */
1565 return !strcmp(ptr1.p_char + idx, ptr2.p_char + idx);
1566 case V4L2_CTRL_TYPE_INTEGER64:
1567 return ptr1.p_s64[idx] == ptr2.p_s64[idx];
1568 case V4L2_CTRL_TYPE_U8:
1569 return ptr1.p_u8[idx] == ptr2.p_u8[idx];
1570 case V4L2_CTRL_TYPE_U16:
1571 return ptr1.p_u16[idx] == ptr2.p_u16[idx];
1572 case V4L2_CTRL_TYPE_U32:
1573 return ptr1.p_u32[idx] == ptr2.p_u32[idx];
1576 return ptr1.p_s32[idx] == ptr2.p_s32[idx];
1577 idx *= ctrl->elem_size;
1578 return !memcmp(ptr1.p_const + idx, ptr2.p_const + idx,
1583 static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx,
1584 union v4l2_ctrl_ptr ptr)
1586 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
1587 void *p = ptr.p + idx * ctrl->elem_size;
1589 if (ctrl->p_def.p_const)
1590 memcpy(p, ctrl->p_def.p_const, ctrl->elem_size);
1592 memset(p, 0, ctrl->elem_size);
1595 * The cast is needed to get rid of a gcc warning complaining that
1596 * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the
1597 * v4l2_ctrl_type enum.
1599 switch ((u32)ctrl->type) {
1600 case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
1601 p_mpeg2_slice_params = p;
1603 p_mpeg2_slice_params->sequence.chroma_format = 1;
1604 /* interlaced top field */
1605 p_mpeg2_slice_params->picture.picture_structure = 1;
1606 p_mpeg2_slice_params->picture.picture_coding_type =
1607 V4L2_MPEG2_PICTURE_CODING_TYPE_I;
1612 static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
1613 union v4l2_ctrl_ptr ptr)
1615 switch (ctrl->type) {
1616 case V4L2_CTRL_TYPE_STRING:
1617 idx *= ctrl->elem_size;
1618 memset(ptr.p_char + idx, ' ', ctrl->minimum);
1619 ptr.p_char[idx + ctrl->minimum] = '\0';
1621 case V4L2_CTRL_TYPE_INTEGER64:
1622 ptr.p_s64[idx] = ctrl->default_value;
1624 case V4L2_CTRL_TYPE_INTEGER:
1625 case V4L2_CTRL_TYPE_INTEGER_MENU:
1626 case V4L2_CTRL_TYPE_MENU:
1627 case V4L2_CTRL_TYPE_BITMASK:
1628 case V4L2_CTRL_TYPE_BOOLEAN:
1629 ptr.p_s32[idx] = ctrl->default_value;
1631 case V4L2_CTRL_TYPE_BUTTON:
1632 case V4L2_CTRL_TYPE_CTRL_CLASS:
1635 case V4L2_CTRL_TYPE_U8:
1636 ptr.p_u8[idx] = ctrl->default_value;
1638 case V4L2_CTRL_TYPE_U16:
1639 ptr.p_u16[idx] = ctrl->default_value;
1641 case V4L2_CTRL_TYPE_U32:
1642 ptr.p_u32[idx] = ctrl->default_value;
1645 std_init_compound(ctrl, idx, ptr);
1650 static void std_log(const struct v4l2_ctrl *ctrl)
1652 union v4l2_ctrl_ptr ptr = ctrl->p_cur;
1654 if (ctrl->is_array) {
1657 for (i = 0; i < ctrl->nr_of_dims; i++)
1658 pr_cont("[%u]", ctrl->dims[i]);
1662 switch (ctrl->type) {
1663 case V4L2_CTRL_TYPE_INTEGER:
1664 pr_cont("%d", *ptr.p_s32);
1666 case V4L2_CTRL_TYPE_BOOLEAN:
1667 pr_cont("%s", *ptr.p_s32 ? "true" : "false");
1669 case V4L2_CTRL_TYPE_MENU:
1670 pr_cont("%s", ctrl->qmenu[*ptr.p_s32]);
1672 case V4L2_CTRL_TYPE_INTEGER_MENU:
1673 pr_cont("%lld", ctrl->qmenu_int[*ptr.p_s32]);
1675 case V4L2_CTRL_TYPE_BITMASK:
1676 pr_cont("0x%08x", *ptr.p_s32);
1678 case V4L2_CTRL_TYPE_INTEGER64:
1679 pr_cont("%lld", *ptr.p_s64);
1681 case V4L2_CTRL_TYPE_STRING:
1682 pr_cont("%s", ptr.p_char);
1684 case V4L2_CTRL_TYPE_U8:
1685 pr_cont("%u", (unsigned)*ptr.p_u8);
1687 case V4L2_CTRL_TYPE_U16:
1688 pr_cont("%u", (unsigned)*ptr.p_u16);
1690 case V4L2_CTRL_TYPE_U32:
1691 pr_cont("%u", (unsigned)*ptr.p_u32);
1694 pr_cont("unknown type %d", ctrl->type);
1700 * Round towards the closest legal value. Be careful when we are
1701 * close to the maximum range of the control type to prevent
1704 #define ROUND_TO_RANGE(val, offset_type, ctrl) \
1706 offset_type offset; \
1707 if ((ctrl)->maximum >= 0 && \
1708 val >= (ctrl)->maximum - (s32)((ctrl)->step / 2)) \
1709 val = (ctrl)->maximum; \
1711 val += (s32)((ctrl)->step / 2); \
1712 val = clamp_t(typeof(val), val, \
1713 (ctrl)->minimum, (ctrl)->maximum); \
1714 offset = (val) - (ctrl)->minimum; \
1715 offset = (ctrl)->step * (offset / (u32)(ctrl)->step); \
1716 val = (ctrl)->minimum + offset; \
1720 /* Validate a new control */
1722 #define zero_padding(s) \
1723 memset(&(s).padding, 0, sizeof((s).padding))
1726 * Compound controls validation requires setting unused fields/flags to zero
1727 * in order to properly detect unchanged controls with std_equal's memcmp.
1729 static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
1730 union v4l2_ctrl_ptr ptr)
1732 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
1733 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
1734 struct v4l2_ctrl_hevc_sps *p_hevc_sps;
1735 struct v4l2_ctrl_hevc_pps *p_hevc_pps;
1736 struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
1737 struct v4l2_area *area;
1738 void *p = ptr.p + idx * ctrl->elem_size;
1741 switch ((u32)ctrl->type) {
1742 case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
1743 p_mpeg2_slice_params = p;
1745 switch (p_mpeg2_slice_params->sequence.chroma_format) {
1754 switch (p_mpeg2_slice_params->picture.intra_dc_precision) {
1755 case 0: /* 8 bits */
1756 case 1: /* 9 bits */
1757 case 2: /* 10 bits */
1758 case 3: /* 11 bits */
1764 switch (p_mpeg2_slice_params->picture.picture_structure) {
1765 case 1: /* interlaced top field */
1766 case 2: /* interlaced bottom field */
1767 case 3: /* progressive */
1773 switch (p_mpeg2_slice_params->picture.picture_coding_type) {
1774 case V4L2_MPEG2_PICTURE_CODING_TYPE_I:
1775 case V4L2_MPEG2_PICTURE_CODING_TYPE_P:
1776 case V4L2_MPEG2_PICTURE_CODING_TYPE_B:
1784 case V4L2_CTRL_TYPE_MPEG2_QUANTIZATION:
1787 case V4L2_CTRL_TYPE_FWHT_PARAMS:
1790 case V4L2_CTRL_TYPE_H264_SPS:
1791 case V4L2_CTRL_TYPE_H264_PPS:
1792 case V4L2_CTRL_TYPE_H264_SCALING_MATRIX:
1793 case V4L2_CTRL_TYPE_H264_SLICE_PARAMS:
1794 case V4L2_CTRL_TYPE_H264_DECODE_PARAMS:
1797 case V4L2_CTRL_TYPE_VP8_FRAME_HEADER:
1798 p_vp8_frame_header = p;
1800 switch (p_vp8_frame_header->num_dct_parts) {
1809 zero_padding(p_vp8_frame_header->segment_header);
1810 zero_padding(p_vp8_frame_header->lf_header);
1811 zero_padding(p_vp8_frame_header->quant_header);
1812 zero_padding(p_vp8_frame_header->entropy_header);
1813 zero_padding(p_vp8_frame_header->coder_state);
1816 case V4L2_CTRL_TYPE_HEVC_SPS:
1819 if (!(p_hevc_sps->flags & V4L2_HEVC_SPS_FLAG_PCM_ENABLED)) {
1820 p_hevc_sps->pcm_sample_bit_depth_luma_minus1 = 0;
1821 p_hevc_sps->pcm_sample_bit_depth_chroma_minus1 = 0;
1822 p_hevc_sps->log2_min_pcm_luma_coding_block_size_minus3 = 0;
1823 p_hevc_sps->log2_diff_max_min_pcm_luma_coding_block_size = 0;
1826 if (!(p_hevc_sps->flags &
1827 V4L2_HEVC_SPS_FLAG_LONG_TERM_REF_PICS_PRESENT))
1828 p_hevc_sps->num_long_term_ref_pics_sps = 0;
1831 case V4L2_CTRL_TYPE_HEVC_PPS:
1834 if (!(p_hevc_pps->flags &
1835 V4L2_HEVC_PPS_FLAG_CU_QP_DELTA_ENABLED))
1836 p_hevc_pps->diff_cu_qp_delta_depth = 0;
1838 if (!(p_hevc_pps->flags & V4L2_HEVC_PPS_FLAG_TILES_ENABLED)) {
1839 p_hevc_pps->num_tile_columns_minus1 = 0;
1840 p_hevc_pps->num_tile_rows_minus1 = 0;
1841 memset(&p_hevc_pps->column_width_minus1, 0,
1842 sizeof(p_hevc_pps->column_width_minus1));
1843 memset(&p_hevc_pps->row_height_minus1, 0,
1844 sizeof(p_hevc_pps->row_height_minus1));
1846 p_hevc_pps->flags &=
1847 ~V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED;
1850 if (p_hevc_pps->flags &
1851 V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER) {
1852 p_hevc_pps->pps_beta_offset_div2 = 0;
1853 p_hevc_pps->pps_tc_offset_div2 = 0;
1856 zero_padding(*p_hevc_pps);
1859 case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
1860 p_hevc_slice_params = p;
1862 if (p_hevc_slice_params->num_active_dpb_entries >
1863 V4L2_HEVC_DPB_ENTRIES_NUM_MAX)
1866 zero_padding(p_hevc_slice_params->pred_weight_table);
1868 for (i = 0; i < p_hevc_slice_params->num_active_dpb_entries;
1870 struct v4l2_hevc_dpb_entry *dpb_entry =
1871 &p_hevc_slice_params->dpb[i];
1873 zero_padding(*dpb_entry);
1876 zero_padding(*p_hevc_slice_params);
1879 case V4L2_CTRL_TYPE_AREA:
1881 if (!area->width || !area->height)
1892 static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
1893 union v4l2_ctrl_ptr ptr)
1899 switch ((u32)ctrl->type) {
1900 case V4L2_CTRL_TYPE_INTEGER:
1901 return ROUND_TO_RANGE(ptr.p_s32[idx], u32, ctrl);
1902 case V4L2_CTRL_TYPE_INTEGER64:
1904 * We can't use the ROUND_TO_RANGE define here due to
1905 * the u64 divide that needs special care.
1907 val = ptr.p_s64[idx];
1908 if (ctrl->maximum >= 0 && val >= ctrl->maximum - (s64)(ctrl->step / 2))
1909 val = ctrl->maximum;
1911 val += (s64)(ctrl->step / 2);
1912 val = clamp_t(s64, val, ctrl->minimum, ctrl->maximum);
1913 offset = val - ctrl->minimum;
1914 do_div(offset, ctrl->step);
1915 ptr.p_s64[idx] = ctrl->minimum + offset * ctrl->step;
1917 case V4L2_CTRL_TYPE_U8:
1918 return ROUND_TO_RANGE(ptr.p_u8[idx], u8, ctrl);
1919 case V4L2_CTRL_TYPE_U16:
1920 return ROUND_TO_RANGE(ptr.p_u16[idx], u16, ctrl);
1921 case V4L2_CTRL_TYPE_U32:
1922 return ROUND_TO_RANGE(ptr.p_u32[idx], u32, ctrl);
1924 case V4L2_CTRL_TYPE_BOOLEAN:
1925 ptr.p_s32[idx] = !!ptr.p_s32[idx];
1928 case V4L2_CTRL_TYPE_MENU:
1929 case V4L2_CTRL_TYPE_INTEGER_MENU:
1930 if (ptr.p_s32[idx] < ctrl->minimum || ptr.p_s32[idx] > ctrl->maximum)
1932 if (ctrl->menu_skip_mask & (1ULL << ptr.p_s32[idx]))
1934 if (ctrl->type == V4L2_CTRL_TYPE_MENU &&
1935 ctrl->qmenu[ptr.p_s32[idx]][0] == '\0')
1939 case V4L2_CTRL_TYPE_BITMASK:
1940 ptr.p_s32[idx] &= ctrl->maximum;
1943 case V4L2_CTRL_TYPE_BUTTON:
1944 case V4L2_CTRL_TYPE_CTRL_CLASS:
1948 case V4L2_CTRL_TYPE_STRING:
1949 idx *= ctrl->elem_size;
1950 len = strlen(ptr.p_char + idx);
1951 if (len < ctrl->minimum)
1953 if ((len - (u32)ctrl->minimum) % (u32)ctrl->step)
1958 return std_validate_compound(ctrl, idx, ptr);
1962 static const struct v4l2_ctrl_type_ops std_type_ops = {
1966 .validate = std_validate,
1969 /* Helper function: copy the given control value back to the caller */
1970 static int ptr_to_user(struct v4l2_ext_control *c,
1971 struct v4l2_ctrl *ctrl,
1972 union v4l2_ctrl_ptr ptr)
1976 if (ctrl->is_ptr && !ctrl->is_string)
1977 return copy_to_user(c->ptr, ptr.p_const, c->size) ?
1980 switch (ctrl->type) {
1981 case V4L2_CTRL_TYPE_STRING:
1982 len = strlen(ptr.p_char);
1983 if (c->size < len + 1) {
1984 c->size = ctrl->elem_size;
1987 return copy_to_user(c->string, ptr.p_char, len + 1) ?
1989 case V4L2_CTRL_TYPE_INTEGER64:
1990 c->value64 = *ptr.p_s64;
1993 c->value = *ptr.p_s32;
1999 /* Helper function: copy the current control value back to the caller */
2000 static int cur_to_user(struct v4l2_ext_control *c,
2001 struct v4l2_ctrl *ctrl)
2003 return ptr_to_user(c, ctrl, ctrl->p_cur);
2006 /* Helper function: copy the new control value back to the caller */
2007 static int new_to_user(struct v4l2_ext_control *c,
2008 struct v4l2_ctrl *ctrl)
2010 return ptr_to_user(c, ctrl, ctrl->p_new);
2013 /* Helper function: copy the request value back to the caller */
2014 static int req_to_user(struct v4l2_ext_control *c,
2015 struct v4l2_ctrl_ref *ref)
2017 return ptr_to_user(c, ref->ctrl, ref->p_req);
2020 /* Helper function: copy the initial control value back to the caller */
2021 static int def_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl)
2025 for (idx = 0; idx < ctrl->elems; idx++)
2026 ctrl->type_ops->init(ctrl, idx, ctrl->p_new);
2028 return ptr_to_user(c, ctrl, ctrl->p_new);
2031 /* Helper function: copy the caller-provider value to the given control value */
2032 static int user_to_ptr(struct v4l2_ext_control *c,
2033 struct v4l2_ctrl *ctrl,
2034 union v4l2_ctrl_ptr ptr)
2040 if (ctrl->is_ptr && !ctrl->is_string) {
2043 ret = copy_from_user(ptr.p, c->ptr, c->size) ? -EFAULT : 0;
2044 if (ret || !ctrl->is_array)
2046 for (idx = c->size / ctrl->elem_size; idx < ctrl->elems; idx++)
2047 ctrl->type_ops->init(ctrl, idx, ptr);
2051 switch (ctrl->type) {
2052 case V4L2_CTRL_TYPE_INTEGER64:
2053 *ptr.p_s64 = c->value64;
2055 case V4L2_CTRL_TYPE_STRING:
2059 if (size > ctrl->maximum + 1)
2060 size = ctrl->maximum + 1;
2061 ret = copy_from_user(ptr.p_char, c->string, size) ? -EFAULT : 0;
2063 char last = ptr.p_char[size - 1];
2065 ptr.p_char[size - 1] = 0;
2066 /* If the string was longer than ctrl->maximum,
2067 then return an error. */
2068 if (strlen(ptr.p_char) == ctrl->maximum && last)
2073 *ptr.p_s32 = c->value;
2079 /* Helper function: copy the caller-provider value as the new control value */
2080 static int user_to_new(struct v4l2_ext_control *c,
2081 struct v4l2_ctrl *ctrl)
2083 return user_to_ptr(c, ctrl, ctrl->p_new);
2086 /* Copy the one value to another. */
2087 static void ptr_to_ptr(struct v4l2_ctrl *ctrl,
2088 union v4l2_ctrl_ptr from, union v4l2_ctrl_ptr to)
2092 memcpy(to.p, from.p_const, ctrl->elems * ctrl->elem_size);
2095 /* Copy the new value to the current value. */
2096 static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags)
2103 /* has_changed is set by cluster_changed */
2104 changed = ctrl->has_changed;
2106 ptr_to_ptr(ctrl, ctrl->p_new, ctrl->p_cur);
2108 if (ch_flags & V4L2_EVENT_CTRL_CH_FLAGS) {
2109 /* Note: CH_FLAGS is only set for auto clusters. */
2111 ~(V4L2_CTRL_FLAG_INACTIVE | V4L2_CTRL_FLAG_VOLATILE);
2112 if (!is_cur_manual(ctrl->cluster[0])) {
2113 ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
2114 if (ctrl->cluster[0]->has_volatiles)
2115 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
2119 if (changed || ch_flags) {
2120 /* If a control was changed that was not one of the controls
2121 modified by the application, then send the event to all. */
2124 send_event(fh, ctrl,
2125 (changed ? V4L2_EVENT_CTRL_CH_VALUE : 0) | ch_flags);
2126 if (ctrl->call_notify && changed && ctrl->handler->notify)
2127 ctrl->handler->notify(ctrl, ctrl->handler->notify_priv);
2131 /* Copy the current value to the new value */
2132 static void cur_to_new(struct v4l2_ctrl *ctrl)
2136 ptr_to_ptr(ctrl, ctrl->p_cur, ctrl->p_new);
2139 /* Copy the new value to the request value */
2140 static void new_to_req(struct v4l2_ctrl_ref *ref)
2144 ptr_to_ptr(ref->ctrl, ref->ctrl->p_new, ref->p_req);
2148 /* Copy the request value to the new value */
2149 static void req_to_new(struct v4l2_ctrl_ref *ref)
2154 ptr_to_ptr(ref->ctrl, ref->req->p_req, ref->ctrl->p_new);
2156 ptr_to_ptr(ref->ctrl, ref->ctrl->p_cur, ref->ctrl->p_new);
2159 /* Return non-zero if one or more of the controls in the cluster has a new
2160 value that differs from the current value. */
2161 static int cluster_changed(struct v4l2_ctrl *master)
2163 bool changed = false;
2167 for (i = 0; i < master->ncontrols; i++) {
2168 struct v4l2_ctrl *ctrl = master->cluster[i];
2169 bool ctrl_changed = false;
2174 if (ctrl->flags & V4L2_CTRL_FLAG_EXECUTE_ON_WRITE)
2175 changed = ctrl_changed = true;
2178 * Set has_changed to false to avoid generating
2179 * the event V4L2_EVENT_CTRL_CH_VALUE
2181 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) {
2182 ctrl->has_changed = false;
2186 for (idx = 0; !ctrl_changed && idx < ctrl->elems; idx++)
2187 ctrl_changed = !ctrl->type_ops->equal(ctrl, idx,
2188 ctrl->p_cur, ctrl->p_new);
2189 ctrl->has_changed = ctrl_changed;
2190 changed |= ctrl->has_changed;
2195 /* Control range checking */
2196 static int check_range(enum v4l2_ctrl_type type,
2197 s64 min, s64 max, u64 step, s64 def)
2200 case V4L2_CTRL_TYPE_BOOLEAN:
2201 if (step != 1 || max > 1 || min < 0)
2204 case V4L2_CTRL_TYPE_U8:
2205 case V4L2_CTRL_TYPE_U16:
2206 case V4L2_CTRL_TYPE_U32:
2207 case V4L2_CTRL_TYPE_INTEGER:
2208 case V4L2_CTRL_TYPE_INTEGER64:
2209 if (step == 0 || min > max || def < min || def > max)
2212 case V4L2_CTRL_TYPE_BITMASK:
2213 if (step || min || !max || (def & ~max))
2216 case V4L2_CTRL_TYPE_MENU:
2217 case V4L2_CTRL_TYPE_INTEGER_MENU:
2218 if (min > max || def < min || def > max)
2220 /* Note: step == menu_skip_mask for menu controls.
2221 So here we check if the default value is masked out. */
2222 if (step && ((1 << def) & step))
2225 case V4L2_CTRL_TYPE_STRING:
2226 if (min > max || min < 0 || step < 1 || def)
2234 /* Validate a new control */
2235 static int validate_new(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr p_new)
2240 for (idx = 0; !err && idx < ctrl->elems; idx++)
2241 err = ctrl->type_ops->validate(ctrl, idx, p_new);
2245 static inline u32 node2id(struct list_head *node)
2247 return list_entry(node, struct v4l2_ctrl_ref, node)->ctrl->id;
2250 /* Set the handler's error code if it wasn't set earlier already */
2251 static inline int handler_set_err(struct v4l2_ctrl_handler *hdl, int err)
2253 if (hdl->error == 0)
2258 /* Initialize the handler */
2259 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
2260 unsigned nr_of_controls_hint,
2261 struct lock_class_key *key, const char *name)
2263 mutex_init(&hdl->_lock);
2264 hdl->lock = &hdl->_lock;
2265 lockdep_set_class_and_name(hdl->lock, key, name);
2266 INIT_LIST_HEAD(&hdl->ctrls);
2267 INIT_LIST_HEAD(&hdl->ctrl_refs);
2268 INIT_LIST_HEAD(&hdl->requests);
2269 INIT_LIST_HEAD(&hdl->requests_queued);
2270 hdl->request_is_queued = false;
2271 hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8;
2272 hdl->buckets = kvmalloc_array(hdl->nr_of_buckets,
2273 sizeof(hdl->buckets[0]),
2274 GFP_KERNEL | __GFP_ZERO);
2275 hdl->error = hdl->buckets ? 0 : -ENOMEM;
2276 media_request_object_init(&hdl->req_obj);
2279 EXPORT_SYMBOL(v4l2_ctrl_handler_init_class);
2281 /* Free all controls and control refs */
2282 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
2284 struct v4l2_ctrl_ref *ref, *next_ref;
2285 struct v4l2_ctrl *ctrl, *next_ctrl;
2286 struct v4l2_subscribed_event *sev, *next_sev;
2288 if (hdl == NULL || hdl->buckets == NULL)
2291 if (!hdl->req_obj.req && !list_empty(&hdl->requests)) {
2292 struct v4l2_ctrl_handler *req, *next_req;
2294 list_for_each_entry_safe(req, next_req, &hdl->requests, requests) {
2295 media_request_object_unbind(&req->req_obj);
2296 media_request_object_put(&req->req_obj);
2299 mutex_lock(hdl->lock);
2300 /* Free all nodes */
2301 list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) {
2302 list_del(&ref->node);
2305 /* Free all controls owned by the handler */
2306 list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) {
2307 list_del(&ctrl->node);
2308 list_for_each_entry_safe(sev, next_sev, &ctrl->ev_subs, node)
2309 list_del(&sev->node);
2312 kvfree(hdl->buckets);
2313 hdl->buckets = NULL;
2316 mutex_unlock(hdl->lock);
2317 mutex_destroy(&hdl->_lock);
2319 EXPORT_SYMBOL(v4l2_ctrl_handler_free);
2321 /* For backwards compatibility: V4L2_CID_PRIVATE_BASE should no longer
2322 be used except in G_CTRL, S_CTRL, QUERYCTRL and QUERYMENU when dealing
2323 with applications that do not use the NEXT_CTRL flag.
2325 We just find the n-th private user control. It's O(N), but that should not
2326 be an issue in this particular case. */
2327 static struct v4l2_ctrl_ref *find_private_ref(
2328 struct v4l2_ctrl_handler *hdl, u32 id)
2330 struct v4l2_ctrl_ref *ref;
2332 id -= V4L2_CID_PRIVATE_BASE;
2333 list_for_each_entry(ref, &hdl->ctrl_refs, node) {
2334 /* Search for private user controls that are compatible with
2336 if (V4L2_CTRL_ID2WHICH(ref->ctrl->id) == V4L2_CTRL_CLASS_USER &&
2337 V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) {
2338 if (!ref->ctrl->is_int)
2348 /* Find a control with the given ID. */
2349 static struct v4l2_ctrl_ref *find_ref(struct v4l2_ctrl_handler *hdl, u32 id)
2351 struct v4l2_ctrl_ref *ref;
2354 id &= V4L2_CTRL_ID_MASK;
2356 /* Old-style private controls need special handling */
2357 if (id >= V4L2_CID_PRIVATE_BASE)
2358 return find_private_ref(hdl, id);
2359 bucket = id % hdl->nr_of_buckets;
2361 /* Simple optimization: cache the last control found */
2362 if (hdl->cached && hdl->cached->ctrl->id == id)
2365 /* Not in cache, search the hash */
2366 ref = hdl->buckets ? hdl->buckets[bucket] : NULL;
2367 while (ref && ref->ctrl->id != id)
2371 hdl->cached = ref; /* cache it! */
2375 /* Find a control with the given ID. Take the handler's lock first. */
2376 static struct v4l2_ctrl_ref *find_ref_lock(
2377 struct v4l2_ctrl_handler *hdl, u32 id)
2379 struct v4l2_ctrl_ref *ref = NULL;
2382 mutex_lock(hdl->lock);
2383 ref = find_ref(hdl, id);
2384 mutex_unlock(hdl->lock);
2389 /* Find a control with the given ID. */
2390 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id)
2392 struct v4l2_ctrl_ref *ref = find_ref_lock(hdl, id);
2394 return ref ? ref->ctrl : NULL;
2396 EXPORT_SYMBOL(v4l2_ctrl_find);
2398 /* Allocate a new v4l2_ctrl_ref and hook it into the handler. */
2399 static int handler_new_ref(struct v4l2_ctrl_handler *hdl,
2400 struct v4l2_ctrl *ctrl,
2401 struct v4l2_ctrl_ref **ctrl_ref,
2402 bool from_other_dev, bool allocate_req)
2404 struct v4l2_ctrl_ref *ref;
2405 struct v4l2_ctrl_ref *new_ref;
2407 u32 class_ctrl = V4L2_CTRL_ID2WHICH(id) | 1;
2408 int bucket = id % hdl->nr_of_buckets; /* which bucket to use */
2409 unsigned int size_extra_req = 0;
2415 * Automatically add the control class if it is not yet present and
2416 * the new control is not a compound control.
2418 if (ctrl->type < V4L2_CTRL_COMPOUND_TYPES &&
2419 id != class_ctrl && find_ref_lock(hdl, class_ctrl) == NULL)
2420 if (!v4l2_ctrl_new_std(hdl, NULL, class_ctrl, 0, 0, 0, 0))
2427 size_extra_req = ctrl->elems * ctrl->elem_size;
2428 new_ref = kzalloc(sizeof(*new_ref) + size_extra_req, GFP_KERNEL);
2430 return handler_set_err(hdl, -ENOMEM);
2431 new_ref->ctrl = ctrl;
2432 new_ref->from_other_dev = from_other_dev;
2434 new_ref->p_req.p = &new_ref[1];
2436 INIT_LIST_HEAD(&new_ref->node);
2438 mutex_lock(hdl->lock);
2440 /* Add immediately at the end of the list if the list is empty, or if
2441 the last element in the list has a lower ID.
2442 This ensures that when elements are added in ascending order the
2443 insertion is an O(1) operation. */
2444 if (list_empty(&hdl->ctrl_refs) || id > node2id(hdl->ctrl_refs.prev)) {
2445 list_add_tail(&new_ref->node, &hdl->ctrl_refs);
2446 goto insert_in_hash;
2449 /* Find insert position in sorted list */
2450 list_for_each_entry(ref, &hdl->ctrl_refs, node) {
2451 if (ref->ctrl->id < id)
2453 /* Don't add duplicates */
2454 if (ref->ctrl->id == id) {
2458 list_add(&new_ref->node, ref->node.prev);
2463 /* Insert the control node in the hash */
2464 new_ref->next = hdl->buckets[bucket];
2465 hdl->buckets[bucket] = new_ref;
2467 *ctrl_ref = new_ref;
2468 if (ctrl->handler == hdl) {
2469 /* By default each control starts in a cluster of its own.
2470 * new_ref->ctrl is basically a cluster array with one
2471 * element, so that's perfect to use as the cluster pointer.
2472 * But only do this for the handler that owns the control.
2474 ctrl->cluster = &new_ref->ctrl;
2475 ctrl->ncontrols = 1;
2479 mutex_unlock(hdl->lock);
2483 /* Add a new control */
2484 static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
2485 const struct v4l2_ctrl_ops *ops,
2486 const struct v4l2_ctrl_type_ops *type_ops,
2487 u32 id, const char *name, enum v4l2_ctrl_type type,
2488 s64 min, s64 max, u64 step, s64 def,
2489 const u32 dims[V4L2_CTRL_MAX_DIMS], u32 elem_size,
2490 u32 flags, const char * const *qmenu,
2491 const s64 *qmenu_int, const union v4l2_ctrl_ptr p_def,
2494 struct v4l2_ctrl *ctrl;
2496 unsigned nr_of_dims = 0;
2499 unsigned tot_ctrl_size;
2507 while (dims && dims[nr_of_dims]) {
2508 elems *= dims[nr_of_dims];
2510 if (nr_of_dims == V4L2_CTRL_MAX_DIMS)
2513 is_array = nr_of_dims > 0;
2515 /* Prefill elem_size for all types handled by std_type_ops */
2516 switch ((u32)type) {
2517 case V4L2_CTRL_TYPE_INTEGER64:
2518 elem_size = sizeof(s64);
2520 case V4L2_CTRL_TYPE_STRING:
2521 elem_size = max + 1;
2523 case V4L2_CTRL_TYPE_U8:
2524 elem_size = sizeof(u8);
2526 case V4L2_CTRL_TYPE_U16:
2527 elem_size = sizeof(u16);
2529 case V4L2_CTRL_TYPE_U32:
2530 elem_size = sizeof(u32);
2532 case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
2533 elem_size = sizeof(struct v4l2_ctrl_mpeg2_slice_params);
2535 case V4L2_CTRL_TYPE_MPEG2_QUANTIZATION:
2536 elem_size = sizeof(struct v4l2_ctrl_mpeg2_quantization);
2538 case V4L2_CTRL_TYPE_FWHT_PARAMS:
2539 elem_size = sizeof(struct v4l2_ctrl_fwht_params);
2541 case V4L2_CTRL_TYPE_H264_SPS:
2542 elem_size = sizeof(struct v4l2_ctrl_h264_sps);
2544 case V4L2_CTRL_TYPE_H264_PPS:
2545 elem_size = sizeof(struct v4l2_ctrl_h264_pps);
2547 case V4L2_CTRL_TYPE_H264_SCALING_MATRIX:
2548 elem_size = sizeof(struct v4l2_ctrl_h264_scaling_matrix);
2550 case V4L2_CTRL_TYPE_H264_SLICE_PARAMS:
2551 elem_size = sizeof(struct v4l2_ctrl_h264_slice_params);
2553 case V4L2_CTRL_TYPE_H264_DECODE_PARAMS:
2554 elem_size = sizeof(struct v4l2_ctrl_h264_decode_params);
2556 case V4L2_CTRL_TYPE_VP8_FRAME_HEADER:
2557 elem_size = sizeof(struct v4l2_ctrl_vp8_frame_header);
2559 case V4L2_CTRL_TYPE_HEVC_SPS:
2560 elem_size = sizeof(struct v4l2_ctrl_hevc_sps);
2562 case V4L2_CTRL_TYPE_HEVC_PPS:
2563 elem_size = sizeof(struct v4l2_ctrl_hevc_pps);
2565 case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
2566 elem_size = sizeof(struct v4l2_ctrl_hevc_slice_params);
2568 case V4L2_CTRL_TYPE_AREA:
2569 elem_size = sizeof(struct v4l2_area);
2572 if (type < V4L2_CTRL_COMPOUND_TYPES)
2573 elem_size = sizeof(s32);
2576 tot_ctrl_size = elem_size * elems;
2579 if (id == 0 || name == NULL || !elem_size ||
2580 id >= V4L2_CID_PRIVATE_BASE ||
2581 (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) ||
2582 (type == V4L2_CTRL_TYPE_INTEGER_MENU && qmenu_int == NULL)) {
2583 handler_set_err(hdl, -ERANGE);
2586 err = check_range(type, min, max, step, def);
2588 handler_set_err(hdl, err);
2592 (type == V4L2_CTRL_TYPE_BUTTON ||
2593 type == V4L2_CTRL_TYPE_CTRL_CLASS)) {
2594 handler_set_err(hdl, -EINVAL);
2599 if (type == V4L2_CTRL_TYPE_BUTTON)
2600 flags |= V4L2_CTRL_FLAG_WRITE_ONLY |
2601 V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
2602 else if (type == V4L2_CTRL_TYPE_CTRL_CLASS)
2603 flags |= V4L2_CTRL_FLAG_READ_ONLY;
2604 else if (type == V4L2_CTRL_TYPE_INTEGER64 ||
2605 type == V4L2_CTRL_TYPE_STRING ||
2606 type >= V4L2_CTRL_COMPOUND_TYPES ||
2608 sz_extra += 2 * tot_ctrl_size;
2610 if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p_const)
2611 sz_extra += elem_size;
2613 ctrl = kvzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL);
2615 handler_set_err(hdl, -ENOMEM);
2619 INIT_LIST_HEAD(&ctrl->node);
2620 INIT_LIST_HEAD(&ctrl->ev_subs);
2621 ctrl->handler = hdl;
2623 ctrl->type_ops = type_ops ? type_ops : &std_type_ops;
2627 ctrl->flags = flags;
2628 ctrl->minimum = min;
2629 ctrl->maximum = max;
2631 ctrl->default_value = def;
2632 ctrl->is_string = !is_array && type == V4L2_CTRL_TYPE_STRING;
2633 ctrl->is_ptr = is_array || type >= V4L2_CTRL_COMPOUND_TYPES || ctrl->is_string;
2634 ctrl->is_int = !ctrl->is_ptr && type != V4L2_CTRL_TYPE_INTEGER64;
2635 ctrl->is_array = is_array;
2636 ctrl->elems = elems;
2637 ctrl->nr_of_dims = nr_of_dims;
2639 memcpy(ctrl->dims, dims, nr_of_dims * sizeof(dims[0]));
2640 ctrl->elem_size = elem_size;
2641 if (type == V4L2_CTRL_TYPE_MENU)
2642 ctrl->qmenu = qmenu;
2643 else if (type == V4L2_CTRL_TYPE_INTEGER_MENU)
2644 ctrl->qmenu_int = qmenu_int;
2646 ctrl->cur.val = ctrl->val = def;
2649 if (!ctrl->is_int) {
2650 ctrl->p_new.p = data;
2651 ctrl->p_cur.p = data + tot_ctrl_size;
2653 ctrl->p_new.p = &ctrl->val;
2654 ctrl->p_cur.p = &ctrl->cur.val;
2657 if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p_const) {
2658 ctrl->p_def.p = ctrl->p_cur.p + tot_ctrl_size;
2659 memcpy(ctrl->p_def.p, p_def.p_const, elem_size);
2662 for (idx = 0; idx < elems; idx++) {
2663 ctrl->type_ops->init(ctrl, idx, ctrl->p_cur);
2664 ctrl->type_ops->init(ctrl, idx, ctrl->p_new);
2667 if (handler_new_ref(hdl, ctrl, NULL, false, false)) {
2671 mutex_lock(hdl->lock);
2672 list_add_tail(&ctrl->node, &hdl->ctrls);
2673 mutex_unlock(hdl->lock);
2677 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
2678 const struct v4l2_ctrl_config *cfg, void *priv)
2681 struct v4l2_ctrl *ctrl;
2682 const char *name = cfg->name;
2683 const char * const *qmenu = cfg->qmenu;
2684 const s64 *qmenu_int = cfg->qmenu_int;
2685 enum v4l2_ctrl_type type = cfg->type;
2686 u32 flags = cfg->flags;
2689 u64 step = cfg->step;
2693 v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step,
2696 is_menu = (type == V4L2_CTRL_TYPE_MENU ||
2697 type == V4L2_CTRL_TYPE_INTEGER_MENU);
2701 WARN_ON(cfg->menu_skip_mask);
2702 if (type == V4L2_CTRL_TYPE_MENU && !qmenu) {
2703 qmenu = v4l2_ctrl_get_menu(cfg->id);
2704 } else if (type == V4L2_CTRL_TYPE_INTEGER_MENU && !qmenu_int) {
2705 handler_set_err(hdl, -EINVAL);
2709 ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->type_ops, cfg->id, name,
2711 is_menu ? cfg->menu_skip_mask : step, def,
2712 cfg->dims, cfg->elem_size,
2713 flags, qmenu, qmenu_int, cfg->p_def, priv);
2715 ctrl->is_private = cfg->is_private;
2718 EXPORT_SYMBOL(v4l2_ctrl_new_custom);
2720 /* Helper function for standard non-menu controls */
2721 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
2722 const struct v4l2_ctrl_ops *ops,
2723 u32 id, s64 min, s64 max, u64 step, s64 def)
2726 enum v4l2_ctrl_type type;
2729 v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
2730 if (type == V4L2_CTRL_TYPE_MENU ||
2731 type == V4L2_CTRL_TYPE_INTEGER_MENU ||
2732 type >= V4L2_CTRL_COMPOUND_TYPES) {
2733 handler_set_err(hdl, -EINVAL);
2736 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
2737 min, max, step, def, NULL, 0,
2738 flags, NULL, NULL, ptr_null, NULL);
2740 EXPORT_SYMBOL(v4l2_ctrl_new_std);
2742 /* Helper function for standard menu controls */
2743 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
2744 const struct v4l2_ctrl_ops *ops,
2745 u32 id, u8 _max, u64 mask, u8 _def)
2747 const char * const *qmenu = NULL;
2748 const s64 *qmenu_int = NULL;
2749 unsigned int qmenu_int_len = 0;
2751 enum v4l2_ctrl_type type;
2758 v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
2760 if (type == V4L2_CTRL_TYPE_MENU)
2761 qmenu = v4l2_ctrl_get_menu(id);
2762 else if (type == V4L2_CTRL_TYPE_INTEGER_MENU)
2763 qmenu_int = v4l2_ctrl_get_int_menu(id, &qmenu_int_len);
2765 if ((!qmenu && !qmenu_int) || (qmenu_int && max > qmenu_int_len)) {
2766 handler_set_err(hdl, -EINVAL);
2769 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
2770 0, max, mask, def, NULL, 0,
2771 flags, qmenu, qmenu_int, ptr_null, NULL);
2773 EXPORT_SYMBOL(v4l2_ctrl_new_std_menu);
2775 /* Helper function for standard menu controls with driver defined menu */
2776 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
2777 const struct v4l2_ctrl_ops *ops, u32 id, u8 _max,
2778 u64 mask, u8 _def, const char * const *qmenu)
2780 enum v4l2_ctrl_type type;
2788 /* v4l2_ctrl_new_std_menu_items() should only be called for
2789 * standard controls without a standard menu.
2791 if (v4l2_ctrl_get_menu(id)) {
2792 handler_set_err(hdl, -EINVAL);
2796 v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
2797 if (type != V4L2_CTRL_TYPE_MENU || qmenu == NULL) {
2798 handler_set_err(hdl, -EINVAL);
2801 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
2802 0, max, mask, def, NULL, 0,
2803 flags, qmenu, NULL, ptr_null, NULL);
2806 EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items);
2808 /* Helper function for standard compound controls */
2809 struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,
2810 const struct v4l2_ctrl_ops *ops, u32 id,
2811 const union v4l2_ctrl_ptr p_def)
2814 enum v4l2_ctrl_type type;
2816 s64 min, max, step, def;
2818 v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
2819 if (type < V4L2_CTRL_COMPOUND_TYPES) {
2820 handler_set_err(hdl, -EINVAL);
2823 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
2824 min, max, step, def, NULL, 0,
2825 flags, NULL, NULL, p_def, NULL);
2827 EXPORT_SYMBOL(v4l2_ctrl_new_std_compound);
2829 /* Helper function for standard integer menu controls */
2830 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
2831 const struct v4l2_ctrl_ops *ops,
2832 u32 id, u8 _max, u8 _def, const s64 *qmenu_int)
2835 enum v4l2_ctrl_type type;
2842 v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
2843 if (type != V4L2_CTRL_TYPE_INTEGER_MENU) {
2844 handler_set_err(hdl, -EINVAL);
2847 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
2848 0, max, 0, def, NULL, 0,
2849 flags, NULL, qmenu_int, ptr_null, NULL);
2851 EXPORT_SYMBOL(v4l2_ctrl_new_int_menu);
2853 /* Add the controls from another handler to our own. */
2854 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
2855 struct v4l2_ctrl_handler *add,
2856 bool (*filter)(const struct v4l2_ctrl *ctrl),
2857 bool from_other_dev)
2859 struct v4l2_ctrl_ref *ref;
2862 /* Do nothing if either handler is NULL or if they are the same */
2863 if (!hdl || !add || hdl == add)
2867 mutex_lock(add->lock);
2868 list_for_each_entry(ref, &add->ctrl_refs, node) {
2869 struct v4l2_ctrl *ctrl = ref->ctrl;
2871 /* Skip handler-private controls. */
2872 if (ctrl->is_private)
2874 /* And control classes */
2875 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
2877 /* Filter any unwanted controls */
2878 if (filter && !filter(ctrl))
2880 ret = handler_new_ref(hdl, ctrl, NULL, from_other_dev, false);
2884 mutex_unlock(add->lock);
2887 EXPORT_SYMBOL(v4l2_ctrl_add_handler);
2889 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl)
2891 if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_TX)
2893 if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_RX)
2896 case V4L2_CID_AUDIO_MUTE:
2897 case V4L2_CID_AUDIO_VOLUME:
2898 case V4L2_CID_AUDIO_BALANCE:
2899 case V4L2_CID_AUDIO_BASS:
2900 case V4L2_CID_AUDIO_TREBLE:
2901 case V4L2_CID_AUDIO_LOUDNESS:
2908 EXPORT_SYMBOL(v4l2_ctrl_radio_filter);
2910 /* Cluster controls */
2911 void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls)
2913 bool has_volatiles = false;
2916 /* The first control is the master control and it must not be NULL */
2917 if (WARN_ON(ncontrols == 0 || controls[0] == NULL))
2920 for (i = 0; i < ncontrols; i++) {
2922 controls[i]->cluster = controls;
2923 controls[i]->ncontrols = ncontrols;
2924 if (controls[i]->flags & V4L2_CTRL_FLAG_VOLATILE)
2925 has_volatiles = true;
2928 controls[0]->has_volatiles = has_volatiles;
2930 EXPORT_SYMBOL(v4l2_ctrl_cluster);
2932 void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls,
2933 u8 manual_val, bool set_volatile)
2935 struct v4l2_ctrl *master = controls[0];
2939 v4l2_ctrl_cluster(ncontrols, controls);
2940 WARN_ON(ncontrols <= 1);
2941 WARN_ON(manual_val < master->minimum || manual_val > master->maximum);
2942 WARN_ON(set_volatile && !has_op(master, g_volatile_ctrl));
2943 master->is_auto = true;
2944 master->has_volatiles = set_volatile;
2945 master->manual_mode_value = manual_val;
2946 master->flags |= V4L2_CTRL_FLAG_UPDATE;
2948 if (!is_cur_manual(master))
2949 flag = V4L2_CTRL_FLAG_INACTIVE |
2950 (set_volatile ? V4L2_CTRL_FLAG_VOLATILE : 0);
2952 for (i = 1; i < ncontrols; i++)
2954 controls[i]->flags |= flag;
2956 EXPORT_SYMBOL(v4l2_ctrl_auto_cluster);
2958 /* Activate/deactivate a control. */
2959 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active)
2961 /* invert since the actual flag is called 'inactive' */
2962 bool inactive = !active;
2969 /* set V4L2_CTRL_FLAG_INACTIVE */
2970 old = test_and_set_bit(4, &ctrl->flags);
2972 /* clear V4L2_CTRL_FLAG_INACTIVE */
2973 old = test_and_clear_bit(4, &ctrl->flags);
2974 if (old != inactive)
2975 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS);
2977 EXPORT_SYMBOL(v4l2_ctrl_activate);
2979 void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
2986 lockdep_assert_held(ctrl->handler->lock);
2989 /* set V4L2_CTRL_FLAG_GRABBED */
2990 old = test_and_set_bit(1, &ctrl->flags);
2992 /* clear V4L2_CTRL_FLAG_GRABBED */
2993 old = test_and_clear_bit(1, &ctrl->flags);
2995 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS);
2997 EXPORT_SYMBOL(__v4l2_ctrl_grab);
2999 /* Log the control name and value */
3000 static void log_ctrl(const struct v4l2_ctrl *ctrl,
3001 const char *prefix, const char *colon)
3003 if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY))
3005 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
3008 pr_info("%s%s%s: ", prefix, colon, ctrl->name);
3010 ctrl->type_ops->log(ctrl);
3012 if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE |
3013 V4L2_CTRL_FLAG_GRABBED |
3014 V4L2_CTRL_FLAG_VOLATILE)) {
3015 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
3016 pr_cont(" inactive");
3017 if (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)
3018 pr_cont(" grabbed");
3019 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE)
3020 pr_cont(" volatile");
3025 /* Log all controls owned by the handler */
3026 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
3029 struct v4l2_ctrl *ctrl;
3030 const char *colon = "";
3037 len = strlen(prefix);
3038 if (len && prefix[len - 1] != ' ')
3040 mutex_lock(hdl->lock);
3041 list_for_each_entry(ctrl, &hdl->ctrls, node)
3042 if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED))
3043 log_ctrl(ctrl, prefix, colon);
3044 mutex_unlock(hdl->lock);
3046 EXPORT_SYMBOL(v4l2_ctrl_handler_log_status);
3048 int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd)
3050 v4l2_ctrl_handler_log_status(sd->ctrl_handler, sd->name);
3053 EXPORT_SYMBOL(v4l2_ctrl_subdev_log_status);
3055 /* Call s_ctrl for all controls owned by the handler */
3056 int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
3058 struct v4l2_ctrl *ctrl;
3064 lockdep_assert_held(hdl->lock);
3066 list_for_each_entry(ctrl, &hdl->ctrls, node)
3069 list_for_each_entry(ctrl, &hdl->ctrls, node) {
3070 struct v4l2_ctrl *master = ctrl->cluster[0];
3073 /* Skip if this control was already handled by a cluster. */
3074 /* Skip button controls and read-only controls. */
3075 if (ctrl->done || ctrl->type == V4L2_CTRL_TYPE_BUTTON ||
3076 (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY))
3079 for (i = 0; i < master->ncontrols; i++) {
3080 if (master->cluster[i]) {
3081 cur_to_new(master->cluster[i]);
3082 master->cluster[i]->is_new = 1;
3083 master->cluster[i]->done = true;
3086 ret = call_op(master, s_ctrl);
3093 EXPORT_SYMBOL_GPL(__v4l2_ctrl_handler_setup);
3095 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
3102 mutex_lock(hdl->lock);
3103 ret = __v4l2_ctrl_handler_setup(hdl);
3104 mutex_unlock(hdl->lock);
3108 EXPORT_SYMBOL(v4l2_ctrl_handler_setup);
3110 /* Implement VIDIOC_QUERY_EXT_CTRL */
3111 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctrl *qc)
3113 const unsigned next_flags = V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND;
3114 u32 id = qc->id & V4L2_CTRL_ID_MASK;
3115 struct v4l2_ctrl_ref *ref;
3116 struct v4l2_ctrl *ctrl;
3121 mutex_lock(hdl->lock);
3123 /* Try to find it */
3124 ref = find_ref(hdl, id);
3126 if ((qc->id & next_flags) && !list_empty(&hdl->ctrl_refs)) {
3128 /* Match any control that is not hidden */
3132 if ((qc->id & next_flags) == V4L2_CTRL_FLAG_NEXT_COMPOUND) {
3133 /* Match any hidden control */
3135 } else if ((qc->id & next_flags) == next_flags) {
3136 /* Match any control, compound or not */
3140 /* Find the next control with ID > qc->id */
3142 /* Did we reach the end of the control list? */
3143 if (id >= node2id(hdl->ctrl_refs.prev)) {
3144 ref = NULL; /* Yes, so there is no next control */
3146 /* We found a control with the given ID, so just get
3147 the next valid one in the list. */
3148 list_for_each_entry_continue(ref, &hdl->ctrl_refs, node) {
3149 is_compound = ref->ctrl->is_array ||
3150 ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
3151 if (id < ref->ctrl->id &&
3152 (is_compound & mask) == match)
3155 if (&ref->node == &hdl->ctrl_refs)
3158 /* No control with the given ID exists, so start
3159 searching for the next largest ID. We know there
3160 is one, otherwise the first 'if' above would have
3162 list_for_each_entry(ref, &hdl->ctrl_refs, node) {
3163 is_compound = ref->ctrl->is_array ||
3164 ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
3165 if (id < ref->ctrl->id &&
3166 (is_compound & mask) == match)
3169 if (&ref->node == &hdl->ctrl_refs)
3173 mutex_unlock(hdl->lock);
3179 memset(qc, 0, sizeof(*qc));
3180 if (id >= V4L2_CID_PRIVATE_BASE)
3184 strscpy(qc->name, ctrl->name, sizeof(qc->name));
3185 qc->flags = user_flags(ctrl);
3186 qc->type = ctrl->type;
3187 qc->elem_size = ctrl->elem_size;
3188 qc->elems = ctrl->elems;
3189 qc->nr_of_dims = ctrl->nr_of_dims;
3190 memcpy(qc->dims, ctrl->dims, qc->nr_of_dims * sizeof(qc->dims[0]));
3191 qc->minimum = ctrl->minimum;
3192 qc->maximum = ctrl->maximum;
3193 qc->default_value = ctrl->default_value;
3194 if (ctrl->type == V4L2_CTRL_TYPE_MENU
3195 || ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU)
3198 qc->step = ctrl->step;
3201 EXPORT_SYMBOL(v4l2_query_ext_ctrl);
3203 /* Implement VIDIOC_QUERYCTRL */
3204 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc)
3206 struct v4l2_query_ext_ctrl qec = { qc->id };
3209 rc = v4l2_query_ext_ctrl(hdl, &qec);
3214 qc->type = qec.type;
3215 qc->flags = qec.flags;
3216 strscpy(qc->name, qec.name, sizeof(qc->name));
3218 case V4L2_CTRL_TYPE_INTEGER:
3219 case V4L2_CTRL_TYPE_BOOLEAN:
3220 case V4L2_CTRL_TYPE_MENU:
3221 case V4L2_CTRL_TYPE_INTEGER_MENU:
3222 case V4L2_CTRL_TYPE_STRING:
3223 case V4L2_CTRL_TYPE_BITMASK:
3224 qc->minimum = qec.minimum;
3225 qc->maximum = qec.maximum;
3226 qc->step = qec.step;
3227 qc->default_value = qec.default_value;
3233 qc->default_value = 0;
3238 EXPORT_SYMBOL(v4l2_queryctrl);
3240 /* Implement VIDIOC_QUERYMENU */
3241 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm)
3243 struct v4l2_ctrl *ctrl;
3246 ctrl = v4l2_ctrl_find(hdl, qm->id);
3252 switch (ctrl->type) {
3253 case V4L2_CTRL_TYPE_MENU:
3254 if (ctrl->qmenu == NULL)
3257 case V4L2_CTRL_TYPE_INTEGER_MENU:
3258 if (ctrl->qmenu_int == NULL)
3265 if (i < ctrl->minimum || i > ctrl->maximum)
3268 /* Use mask to see if this menu item should be skipped */
3269 if (ctrl->menu_skip_mask & (1ULL << i))
3271 /* Empty menu items should also be skipped */
3272 if (ctrl->type == V4L2_CTRL_TYPE_MENU) {
3273 if (ctrl->qmenu[i] == NULL || ctrl->qmenu[i][0] == '\0')
3275 strscpy(qm->name, ctrl->qmenu[i], sizeof(qm->name));
3277 qm->value = ctrl->qmenu_int[i];
3281 EXPORT_SYMBOL(v4l2_querymenu);
3283 static int v4l2_ctrl_request_clone(struct v4l2_ctrl_handler *hdl,
3284 const struct v4l2_ctrl_handler *from)
3286 struct v4l2_ctrl_ref *ref;
3289 if (WARN_ON(!hdl || hdl == from))
3295 WARN_ON(hdl->lock != &hdl->_lock);
3297 mutex_lock(from->lock);
3298 list_for_each_entry(ref, &from->ctrl_refs, node) {
3299 struct v4l2_ctrl *ctrl = ref->ctrl;
3300 struct v4l2_ctrl_ref *new_ref;
3302 /* Skip refs inherited from other devices */
3303 if (ref->from_other_dev)
3306 if (ctrl->type == V4L2_CTRL_TYPE_BUTTON)
3308 err = handler_new_ref(hdl, ctrl, &new_ref, false, true);
3312 mutex_unlock(from->lock);
3316 static void v4l2_ctrl_request_queue(struct media_request_object *obj)
3318 struct v4l2_ctrl_handler *hdl =
3319 container_of(obj, struct v4l2_ctrl_handler, req_obj);
3320 struct v4l2_ctrl_handler *main_hdl = obj->priv;
3321 struct v4l2_ctrl_handler *prev_hdl = NULL;
3322 struct v4l2_ctrl_ref *ref_ctrl, *ref_ctrl_prev = NULL;
3324 mutex_lock(main_hdl->lock);
3325 if (list_empty(&main_hdl->requests_queued))
3328 prev_hdl = list_last_entry(&main_hdl->requests_queued,
3329 struct v4l2_ctrl_handler, requests_queued);
3331 * Note: prev_hdl and hdl must contain the same list of control
3332 * references, so if any differences are detected then that is a
3333 * driver bug and the WARN_ON is triggered.
3335 mutex_lock(prev_hdl->lock);
3336 ref_ctrl_prev = list_first_entry(&prev_hdl->ctrl_refs,
3337 struct v4l2_ctrl_ref, node);
3338 list_for_each_entry(ref_ctrl, &hdl->ctrl_refs, node) {
3341 while (ref_ctrl_prev->ctrl->id < ref_ctrl->ctrl->id) {
3342 /* Should never happen, but just in case... */
3343 if (list_is_last(&ref_ctrl_prev->node,
3344 &prev_hdl->ctrl_refs))
3346 ref_ctrl_prev = list_next_entry(ref_ctrl_prev, node);
3348 if (WARN_ON(ref_ctrl_prev->ctrl->id != ref_ctrl->ctrl->id))
3350 ref_ctrl->req = ref_ctrl_prev->req;
3352 mutex_unlock(prev_hdl->lock);
3354 list_add_tail(&hdl->requests_queued, &main_hdl->requests_queued);
3355 hdl->request_is_queued = true;
3356 mutex_unlock(main_hdl->lock);
3359 static void v4l2_ctrl_request_unbind(struct media_request_object *obj)
3361 struct v4l2_ctrl_handler *hdl =
3362 container_of(obj, struct v4l2_ctrl_handler, req_obj);
3363 struct v4l2_ctrl_handler *main_hdl = obj->priv;
3365 list_del_init(&hdl->requests);
3366 mutex_lock(main_hdl->lock);
3367 if (hdl->request_is_queued) {
3368 list_del_init(&hdl->requests_queued);
3369 hdl->request_is_queued = false;
3371 mutex_unlock(main_hdl->lock);
3374 static void v4l2_ctrl_request_release(struct media_request_object *obj)
3376 struct v4l2_ctrl_handler *hdl =
3377 container_of(obj, struct v4l2_ctrl_handler, req_obj);
3379 v4l2_ctrl_handler_free(hdl);
3383 static const struct media_request_object_ops req_ops = {
3384 .queue = v4l2_ctrl_request_queue,
3385 .unbind = v4l2_ctrl_request_unbind,
3386 .release = v4l2_ctrl_request_release,
3389 struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
3390 struct v4l2_ctrl_handler *parent)
3392 struct media_request_object *obj;
3394 if (WARN_ON(req->state != MEDIA_REQUEST_STATE_VALIDATING &&
3395 req->state != MEDIA_REQUEST_STATE_QUEUED))
3398 obj = media_request_object_find(req, &req_ops, parent);
3400 return container_of(obj, struct v4l2_ctrl_handler, req_obj);
3403 EXPORT_SYMBOL_GPL(v4l2_ctrl_request_hdl_find);
3406 v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id)
3408 struct v4l2_ctrl_ref *ref = find_ref_lock(hdl, id);
3410 return (ref && ref->req == ref) ? ref->ctrl : NULL;
3412 EXPORT_SYMBOL_GPL(v4l2_ctrl_request_hdl_ctrl_find);
3414 static int v4l2_ctrl_request_bind(struct media_request *req,
3415 struct v4l2_ctrl_handler *hdl,
3416 struct v4l2_ctrl_handler *from)
3420 ret = v4l2_ctrl_request_clone(hdl, from);
3423 ret = media_request_object_bind(req, &req_ops,
3424 from, false, &hdl->req_obj);
3426 list_add_tail(&hdl->requests, &from->requests);
3431 /* Some general notes on the atomic requirements of VIDIOC_G/TRY/S_EXT_CTRLS:
3433 It is not a fully atomic operation, just best-effort only. After all, if
3434 multiple controls have to be set through multiple i2c writes (for example)
3435 then some initial writes may succeed while others fail. Thus leaving the
3436 system in an inconsistent state. The question is how much effort you are
3437 willing to spend on trying to make something atomic that really isn't.
3439 From the point of view of an application the main requirement is that
3440 when you call VIDIOC_S_EXT_CTRLS and some values are invalid then an
3441 error should be returned without actually affecting any controls.
3443 If all the values are correct, then it is acceptable to just give up
3444 in case of low-level errors.
3446 It is important though that the application can tell when only a partial
3447 configuration was done. The way we do that is through the error_idx field
3448 of struct v4l2_ext_controls: if that is equal to the count field then no
3449 controls were affected. Otherwise all controls before that index were
3450 successful in performing their 'get' or 'set' operation, the control at
3451 the given index failed, and you don't know what happened with the controls
3452 after the failed one. Since if they were part of a control cluster they
3453 could have been successfully processed (if a cluster member was encountered
3454 at index < error_idx), they could have failed (if a cluster member was at
3455 error_idx), or they may not have been processed yet (if the first cluster
3456 member appeared after error_idx).
3458 It is all fairly theoretical, though. In practice all you can do is to
3459 bail out. If error_idx == count, then it is an application bug. If
3460 error_idx < count then it is only an application bug if the error code was
3461 EBUSY. That usually means that something started streaming just when you
3462 tried to set the controls. In all other cases it is a driver/hardware
3463 problem and all you can do is to retry or bail out.
3465 Note that these rules do not apply to VIDIOC_TRY_EXT_CTRLS: since that
3466 never modifies controls the error_idx is just set to whatever control
3467 has an invalid value.
3470 /* Prepare for the extended g/s/try functions.
3471 Find the controls in the control array and do some basic checks. */
3472 static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
3473 struct v4l2_ext_controls *cs,
3474 struct v4l2_ctrl_helper *helpers,
3475 struct video_device *vdev,
3478 struct v4l2_ctrl_helper *h;
3479 bool have_clusters = false;
3482 for (i = 0, h = helpers; i < cs->count; i++, h++) {
3483 struct v4l2_ext_control *c = &cs->controls[i];
3484 struct v4l2_ctrl_ref *ref;
3485 struct v4l2_ctrl *ctrl;
3486 u32 id = c->id & V4L2_CTRL_ID_MASK;
3491 cs->which != V4L2_CTRL_WHICH_DEF_VAL &&
3492 cs->which != V4L2_CTRL_WHICH_REQUEST_VAL &&
3493 V4L2_CTRL_ID2WHICH(id) != cs->which) {
3495 "invalid which 0x%x or control id 0x%x\n",
3500 /* Old-style private controls are not allowed for
3501 extended controls */
3502 if (id >= V4L2_CID_PRIVATE_BASE) {
3504 "old-style private controls not allowed\n");
3507 ref = find_ref_lock(hdl, id);
3509 dprintk(vdev, "cannot find control id 0x%x\n", id);
3514 if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED) {
3515 dprintk(vdev, "control id 0x%x is disabled\n", id);
3519 if (ctrl->cluster[0]->ncontrols > 1)
3520 have_clusters = true;
3521 if (ctrl->cluster[0] != ctrl)
3522 ref = find_ref_lock(hdl, ctrl->cluster[0]->id);
3523 if (ctrl->is_ptr && !ctrl->is_string) {
3524 unsigned tot_size = ctrl->elems * ctrl->elem_size;
3526 if (c->size < tot_size) {
3528 * In the get case the application first
3529 * queries to obtain the size of the control.
3536 "pointer control id 0x%x size too small, %d bytes but %d bytes needed\n",
3537 id, c->size, tot_size);
3542 /* Store the ref to the master control of the cluster */
3544 /* Initially set next to 0, meaning that there is no other
3545 control in this helper array belonging to the same
3550 /* We are done if there were no controls that belong to a multi-
3555 /* The code below figures out in O(n) time which controls in the list
3556 belong to the same cluster. */
3558 /* This has to be done with the handler lock taken. */
3559 mutex_lock(hdl->lock);
3561 /* First zero the helper field in the master control references */
3562 for (i = 0; i < cs->count; i++)
3563 helpers[i].mref->helper = NULL;
3564 for (i = 0, h = helpers; i < cs->count; i++, h++) {
3565 struct v4l2_ctrl_ref *mref = h->mref;
3567 /* If the mref->helper is set, then it points to an earlier
3568 helper that belongs to the same cluster. */
3570 /* Set the next field of mref->helper to the current
3571 index: this means that that earlier helper now
3572 points to the next helper in the same cluster. */
3573 mref->helper->next = i;
3574 /* mref should be set only for the first helper in the
3575 cluster, clear the others. */
3578 /* Point the mref helper to the current helper struct. */
3581 mutex_unlock(hdl->lock);
3585 /* Handles the corner case where cs->count == 0. It checks whether the
3586 specified control class exists. If that class ID is 0, then it checks
3587 whether there are any controls at all. */
3588 static int class_check(struct v4l2_ctrl_handler *hdl, u32 which)
3590 if (which == 0 || which == V4L2_CTRL_WHICH_DEF_VAL ||
3591 which == V4L2_CTRL_WHICH_REQUEST_VAL)
3593 return find_ref_lock(hdl, which | 1) ? 0 : -EINVAL;
3596 /* Get extended controls. Allocates the helpers array if needed. */
3597 static int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *hdl,
3598 struct v4l2_ext_controls *cs,
3599 struct video_device *vdev)
3601 struct v4l2_ctrl_helper helper[4];
3602 struct v4l2_ctrl_helper *helpers = helper;
3607 def_value = (cs->which == V4L2_CTRL_WHICH_DEF_VAL);
3609 cs->error_idx = cs->count;
3610 cs->which = V4L2_CTRL_ID2WHICH(cs->which);
3616 return class_check(hdl, cs->which);
3618 if (cs->count > ARRAY_SIZE(helper)) {
3619 helpers = kvmalloc_array(cs->count, sizeof(helper[0]),
3621 if (helpers == NULL)
3625 ret = prepare_ext_ctrls(hdl, cs, helpers, vdev, true);
3626 cs->error_idx = cs->count;
3628 for (i = 0; !ret && i < cs->count; i++)
3629 if (helpers[i].ref->ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
3632 for (i = 0; !ret && i < cs->count; i++) {
3633 int (*ctrl_to_user)(struct v4l2_ext_control *c,
3634 struct v4l2_ctrl *ctrl);
3635 struct v4l2_ctrl *master;
3637 ctrl_to_user = def_value ? def_to_user : cur_to_user;
3639 if (helpers[i].mref == NULL)
3642 master = helpers[i].mref->ctrl;
3645 v4l2_ctrl_lock(master);
3647 /* g_volatile_ctrl will update the new control values */
3649 ((master->flags & V4L2_CTRL_FLAG_VOLATILE) ||
3650 (master->has_volatiles && !is_cur_manual(master)))) {
3651 for (j = 0; j < master->ncontrols; j++)
3652 cur_to_new(master->cluster[j]);
3653 ret = call_op(master, g_volatile_ctrl);
3654 ctrl_to_user = new_to_user;
3656 /* If OK, then copy the current (for non-volatile controls)
3657 or the new (for volatile controls) control values to the
3663 if (helpers[idx].ref->req)
3664 ret = req_to_user(cs->controls + idx,
3665 helpers[idx].ref->req);
3667 ret = ctrl_to_user(cs->controls + idx,
3668 helpers[idx].ref->ctrl);
3669 idx = helpers[idx].next;
3670 } while (!ret && idx);
3672 v4l2_ctrl_unlock(master);
3675 if (cs->count > ARRAY_SIZE(helper))
3680 static struct media_request_object *
3681 v4l2_ctrls_find_req_obj(struct v4l2_ctrl_handler *hdl,
3682 struct media_request *req, bool set)
3684 struct media_request_object *obj;
3685 struct v4l2_ctrl_handler *new_hdl;
3689 return ERR_CAST(req);
3691 if (set && WARN_ON(req->state != MEDIA_REQUEST_STATE_UPDATING))
3692 return ERR_PTR(-EBUSY);
3694 obj = media_request_object_find(req, &req_ops, hdl);
3698 return ERR_PTR(-ENOENT);
3700 new_hdl = kzalloc(sizeof(*new_hdl), GFP_KERNEL);
3702 return ERR_PTR(-ENOMEM);
3704 obj = &new_hdl->req_obj;
3705 ret = v4l2_ctrl_handler_init(new_hdl, (hdl->nr_of_buckets - 1) * 8);
3707 ret = v4l2_ctrl_request_bind(req, new_hdl, hdl);
3711 return ERR_PTR(ret);
3714 media_request_object_get(obj);
3718 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
3719 struct media_device *mdev, struct v4l2_ext_controls *cs)
3721 struct media_request_object *obj = NULL;
3722 struct media_request *req = NULL;
3725 if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) {
3726 if (!mdev || cs->request_fd < 0)
3729 req = media_request_get_by_fd(mdev, cs->request_fd);
3731 return PTR_ERR(req);
3733 if (req->state != MEDIA_REQUEST_STATE_COMPLETE) {
3734 media_request_put(req);
3738 ret = media_request_lock_for_access(req);
3740 media_request_put(req);
3744 obj = v4l2_ctrls_find_req_obj(hdl, req, false);
3746 media_request_unlock_for_access(req);
3747 media_request_put(req);
3748 return PTR_ERR(obj);
3751 hdl = container_of(obj, struct v4l2_ctrl_handler,
3755 ret = v4l2_g_ext_ctrls_common(hdl, cs, vdev);
3758 media_request_unlock_for_access(req);
3759 media_request_object_put(obj);
3760 media_request_put(req);
3764 EXPORT_SYMBOL(v4l2_g_ext_ctrls);
3766 /* Helper function to get a single control */
3767 static int get_ctrl(struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c)
3769 struct v4l2_ctrl *master = ctrl->cluster[0];
3773 /* Compound controls are not supported. The new_to_user() and
3774 * cur_to_user() calls below would need to be modified not to access
3775 * userspace memory when called from get_ctrl().
3777 if (!ctrl->is_int && ctrl->type != V4L2_CTRL_TYPE_INTEGER64)
3780 if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
3783 v4l2_ctrl_lock(master);
3784 /* g_volatile_ctrl will update the current control values */
3785 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) {
3786 for (i = 0; i < master->ncontrols; i++)
3787 cur_to_new(master->cluster[i]);
3788 ret = call_op(master, g_volatile_ctrl);
3789 new_to_user(c, ctrl);
3791 cur_to_user(c, ctrl);
3793 v4l2_ctrl_unlock(master);
3797 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control)
3799 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id);
3800 struct v4l2_ext_control c;
3803 if (ctrl == NULL || !ctrl->is_int)
3805 ret = get_ctrl(ctrl, &c);
3806 control->value = c.value;
3809 EXPORT_SYMBOL(v4l2_g_ctrl);
3811 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl)
3813 struct v4l2_ext_control c;
3815 /* It's a driver bug if this happens. */
3816 if (WARN_ON(!ctrl->is_int))
3822 EXPORT_SYMBOL(v4l2_ctrl_g_ctrl);
3824 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl)
3826 struct v4l2_ext_control c;
3828 /* It's a driver bug if this happens. */
3829 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64))
3835 EXPORT_SYMBOL(v4l2_ctrl_g_ctrl_int64);
3838 /* Core function that calls try/s_ctrl and ensures that the new value is
3839 copied to the current value on a set.
3840 Must be called with ctrl->handler->lock held. */
3841 static int try_or_set_cluster(struct v4l2_fh *fh, struct v4l2_ctrl *master,
3842 bool set, u32 ch_flags)
3848 /* Go through the cluster and either validate the new value or
3849 (if no new value was set), copy the current value to the new
3850 value, ensuring a consistent view for the control ops when
3852 for (i = 0; i < master->ncontrols; i++) {
3853 struct v4l2_ctrl *ctrl = master->cluster[i];
3858 if (!ctrl->is_new) {
3862 /* Check again: it may have changed since the
3863 previous check in try_or_set_ext_ctrls(). */
3864 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED))
3868 ret = call_op(master, try_ctrl);
3870 /* Don't set if there is no change */
3871 if (ret || !set || !cluster_changed(master))
3873 ret = call_op(master, s_ctrl);
3877 /* If OK, then make the new values permanent. */
3878 update_flag = is_cur_manual(master) != is_new_manual(master);
3880 for (i = 0; i < master->ncontrols; i++) {
3882 * If we switch from auto to manual mode, and this cluster
3883 * contains volatile controls, then all non-master controls
3884 * have to be marked as changed. The 'new' value contains
3885 * the volatile value (obtained by update_from_auto_cluster),
3886 * which now has to become the current value.
3888 if (i && update_flag && is_new_manual(master) &&
3889 master->has_volatiles && master->cluster[i])
3890 master->cluster[i]->has_changed = true;
3892 new_to_cur(fh, master->cluster[i], ch_flags |
3893 ((update_flag && i > 0) ? V4L2_EVENT_CTRL_CH_FLAGS : 0));
3898 /* Validate controls. */
3899 static int validate_ctrls(struct v4l2_ext_controls *cs,
3900 struct v4l2_ctrl_helper *helpers,
3901 struct video_device *vdev,
3907 cs->error_idx = cs->count;
3908 for (i = 0; i < cs->count; i++) {
3909 struct v4l2_ctrl *ctrl = helpers[i].ref->ctrl;
3910 union v4l2_ctrl_ptr p_new;
3914 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) {
3916 "control id 0x%x is read-only\n",
3920 /* This test is also done in try_set_control_cluster() which
3921 is called in atomic context, so that has the final say,
3922 but it makes sense to do an up-front check as well. Once
3923 an error occurs in try_set_control_cluster() some other
3924 controls may have been set already and we want to do a
3925 best-effort to avoid that. */
3926 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) {
3928 "control id 0x%x is grabbed, cannot set\n",
3933 * Skip validation for now if the payload needs to be copied
3934 * from userspace into kernelspace. We'll validate those later.
3938 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
3939 p_new.p_s64 = &cs->controls[i].value64;
3941 p_new.p_s32 = &cs->controls[i].value;
3942 ret = validate_new(ctrl, p_new);
3949 /* Obtain the current volatile values of an autocluster and mark them
3951 static void update_from_auto_cluster(struct v4l2_ctrl *master)
3955 for (i = 1; i < master->ncontrols; i++)
3956 cur_to_new(master->cluster[i]);
3957 if (!call_op(master, g_volatile_ctrl))
3958 for (i = 1; i < master->ncontrols; i++)
3959 if (master->cluster[i])
3960 master->cluster[i]->is_new = 1;
3963 /* Try or try-and-set controls */
3964 static int try_set_ext_ctrls_common(struct v4l2_fh *fh,
3965 struct v4l2_ctrl_handler *hdl,
3966 struct v4l2_ext_controls *cs,
3967 struct video_device *vdev, bool set)
3969 struct v4l2_ctrl_helper helper[4];
3970 struct v4l2_ctrl_helper *helpers = helper;
3974 cs->error_idx = cs->count;
3976 /* Default value cannot be changed */
3977 if (cs->which == V4L2_CTRL_WHICH_DEF_VAL) {
3978 dprintk(vdev, "%s: cannot change default value\n",
3979 video_device_node_name(vdev));
3983 cs->which = V4L2_CTRL_ID2WHICH(cs->which);
3986 dprintk(vdev, "%s: invalid null control handler\n",
3987 video_device_node_name(vdev));
3992 return class_check(hdl, cs->which);
3994 if (cs->count > ARRAY_SIZE(helper)) {
3995 helpers = kvmalloc_array(cs->count, sizeof(helper[0]),
4000 ret = prepare_ext_ctrls(hdl, cs, helpers, vdev, false);
4002 ret = validate_ctrls(cs, helpers, vdev, set);
4004 cs->error_idx = cs->count;
4005 for (i = 0; !ret && i < cs->count; i++) {
4006 struct v4l2_ctrl *master;
4009 if (helpers[i].mref == NULL)
4013 master = helpers[i].mref->ctrl;
4014 v4l2_ctrl_lock(master);
4016 /* Reset the 'is_new' flags of the cluster */
4017 for (j = 0; j < master->ncontrols; j++)
4018 if (master->cluster[j])
4019 master->cluster[j]->is_new = 0;
4021 /* For volatile autoclusters that are currently in auto mode
4022 we need to discover if it will be set to manual mode.
4023 If so, then we have to copy the current volatile values
4024 first since those will become the new manual values (which
4025 may be overwritten by explicit new values from this set
4027 if (master->is_auto && master->has_volatiles &&
4028 !is_cur_manual(master)) {
4029 /* Pick an initial non-manual value */
4030 s32 new_auto_val = master->manual_mode_value + 1;
4034 /* Check if the auto control is part of the
4035 list, and remember the new value. */
4036 if (helpers[tmp_idx].ref->ctrl == master)
4037 new_auto_val = cs->controls[tmp_idx].value;
4038 tmp_idx = helpers[tmp_idx].next;
4040 /* If the new value == the manual value, then copy
4041 the current volatile values. */
4042 if (new_auto_val == master->manual_mode_value)
4043 update_from_auto_cluster(master);
4046 /* Copy the new caller-supplied control values.
4047 user_to_new() sets 'is_new' to 1. */
4049 struct v4l2_ctrl *ctrl = helpers[idx].ref->ctrl;
4051 ret = user_to_new(cs->controls + idx, ctrl);
4052 if (!ret && ctrl->is_ptr)
4053 ret = validate_new(ctrl, ctrl->p_new);
4054 idx = helpers[idx].next;
4055 } while (!ret && idx);
4058 ret = try_or_set_cluster(fh, master,
4059 !hdl->req_obj.req && set, 0);
4060 if (!ret && hdl->req_obj.req && set) {
4061 for (j = 0; j < master->ncontrols; j++) {
4062 struct v4l2_ctrl_ref *ref =
4063 find_ref(hdl, master->cluster[j]->id);
4069 /* Copy the new values back to userspace. */
4073 ret = new_to_user(cs->controls + idx,
4074 helpers[idx].ref->ctrl);
4075 idx = helpers[idx].next;
4076 } while (!ret && idx);
4078 v4l2_ctrl_unlock(master);
4081 if (cs->count > ARRAY_SIZE(helper))
4086 static int try_set_ext_ctrls(struct v4l2_fh *fh,
4087 struct v4l2_ctrl_handler *hdl,
4088 struct video_device *vdev,
4089 struct media_device *mdev,
4090 struct v4l2_ext_controls *cs, bool set)
4092 struct media_request_object *obj = NULL;
4093 struct media_request *req = NULL;
4096 if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) {
4098 dprintk(vdev, "%s: missing media device\n",
4099 video_device_node_name(vdev));
4103 if (cs->request_fd < 0) {
4104 dprintk(vdev, "%s: invalid request fd %d\n",
4105 video_device_node_name(vdev), cs->request_fd);
4109 req = media_request_get_by_fd(mdev, cs->request_fd);
4111 dprintk(vdev, "%s: cannot find request fd %d\n",
4112 video_device_node_name(vdev), cs->request_fd);
4113 return PTR_ERR(req);
4116 ret = media_request_lock_for_update(req);
4118 dprintk(vdev, "%s: cannot lock request fd %d\n",
4119 video_device_node_name(vdev), cs->request_fd);
4120 media_request_put(req);
4124 obj = v4l2_ctrls_find_req_obj(hdl, req, set);
4127 "%s: cannot find request object for request fd %d\n",
4128 video_device_node_name(vdev),
4130 media_request_unlock_for_update(req);
4131 media_request_put(req);
4132 return PTR_ERR(obj);
4134 hdl = container_of(obj, struct v4l2_ctrl_handler,
4138 ret = try_set_ext_ctrls_common(fh, hdl, cs, vdev, set);
4141 "%s: try_set_ext_ctrls_common failed (%d)\n",
4142 video_device_node_name(vdev), ret);
4145 media_request_unlock_for_update(req);
4146 media_request_object_put(obj);
4147 media_request_put(req);
4153 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
4154 struct video_device *vdev,
4155 struct media_device *mdev,
4156 struct v4l2_ext_controls *cs)
4158 return try_set_ext_ctrls(NULL, hdl, vdev, mdev, cs, false);
4160 EXPORT_SYMBOL(v4l2_try_ext_ctrls);
4162 int v4l2_s_ext_ctrls(struct v4l2_fh *fh,
4163 struct v4l2_ctrl_handler *hdl,
4164 struct video_device *vdev,
4165 struct media_device *mdev,
4166 struct v4l2_ext_controls *cs)
4168 return try_set_ext_ctrls(fh, hdl, vdev, mdev, cs, true);
4170 EXPORT_SYMBOL(v4l2_s_ext_ctrls);
4172 /* Helper function for VIDIOC_S_CTRL compatibility */
4173 static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags)
4175 struct v4l2_ctrl *master = ctrl->cluster[0];
4179 /* Reset the 'is_new' flags of the cluster */
4180 for (i = 0; i < master->ncontrols; i++)
4181 if (master->cluster[i])
4182 master->cluster[i]->is_new = 0;
4184 ret = validate_new(ctrl, ctrl->p_new);
4188 /* For autoclusters with volatiles that are switched from auto to
4189 manual mode we have to update the current volatile values since
4190 those will become the initial manual values after such a switch. */
4191 if (master->is_auto && master->has_volatiles && ctrl == master &&
4192 !is_cur_manual(master) && ctrl->val == master->manual_mode_value)
4193 update_from_auto_cluster(master);
4196 return try_or_set_cluster(fh, master, true, ch_flags);
4199 /* Helper function for VIDIOC_S_CTRL compatibility */
4200 static int set_ctrl_lock(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
4201 struct v4l2_ext_control *c)
4205 v4l2_ctrl_lock(ctrl);
4206 user_to_new(c, ctrl);
4207 ret = set_ctrl(fh, ctrl, 0);
4209 cur_to_user(c, ctrl);
4210 v4l2_ctrl_unlock(ctrl);
4214 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
4215 struct v4l2_control *control)
4217 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id);
4218 struct v4l2_ext_control c = { control->id };
4221 if (ctrl == NULL || !ctrl->is_int)
4224 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
4227 c.value = control->value;
4228 ret = set_ctrl_lock(fh, ctrl, &c);
4229 control->value = c.value;
4232 EXPORT_SYMBOL(v4l2_s_ctrl);
4234 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
4236 lockdep_assert_held(ctrl->handler->lock);
4238 /* It's a driver bug if this happens. */
4239 if (WARN_ON(!ctrl->is_int))
4242 return set_ctrl(NULL, ctrl, 0);
4244 EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl);
4246 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
4248 lockdep_assert_held(ctrl->handler->lock);
4250 /* It's a driver bug if this happens. */
4251 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64))
4253 *ctrl->p_new.p_s64 = val;
4254 return set_ctrl(NULL, ctrl, 0);
4256 EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_int64);
4258 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
4260 lockdep_assert_held(ctrl->handler->lock);
4262 /* It's a driver bug if this happens. */
4263 if (WARN_ON(ctrl->type != V4L2_CTRL_TYPE_STRING))
4265 strscpy(ctrl->p_new.p_char, s, ctrl->maximum + 1);
4266 return set_ctrl(NULL, ctrl, 0);
4268 EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_string);
4270 int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
4271 enum v4l2_ctrl_type type, const void *p)
4273 lockdep_assert_held(ctrl->handler->lock);
4275 /* It's a driver bug if this happens. */
4276 if (WARN_ON(ctrl->type != type))
4278 memcpy(ctrl->p_new.p, p, ctrl->elems * ctrl->elem_size);
4279 return set_ctrl(NULL, ctrl, 0);
4281 EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_compound);
4283 void v4l2_ctrl_request_complete(struct media_request *req,
4284 struct v4l2_ctrl_handler *main_hdl)
4286 struct media_request_object *obj;
4287 struct v4l2_ctrl_handler *hdl;
4288 struct v4l2_ctrl_ref *ref;
4290 if (!req || !main_hdl)
4294 * Note that it is valid if nothing was found. It means
4295 * that this request doesn't have any controls and so just
4296 * wants to leave the controls unchanged.
4298 obj = media_request_object_find(req, &req_ops, main_hdl);
4301 hdl = container_of(obj, struct v4l2_ctrl_handler, req_obj);
4303 list_for_each_entry(ref, &hdl->ctrl_refs, node) {
4304 struct v4l2_ctrl *ctrl = ref->ctrl;
4305 struct v4l2_ctrl *master = ctrl->cluster[0];
4308 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) {
4311 v4l2_ctrl_lock(master);
4312 /* g_volatile_ctrl will update the current control values */
4313 for (i = 0; i < master->ncontrols; i++)
4314 cur_to_new(master->cluster[i]);
4315 call_op(master, g_volatile_ctrl);
4317 v4l2_ctrl_unlock(master);
4320 if (ref->req == ref)
4323 v4l2_ctrl_lock(ctrl);
4325 ptr_to_ptr(ctrl, ref->req->p_req, ref->p_req);
4327 ptr_to_ptr(ctrl, ctrl->p_cur, ref->p_req);
4329 * Set ref->req to ensure that when userspace wants to
4330 * obtain the controls of this request it will take
4331 * this value and not the current value of the control.
4335 v4l2_ctrl_unlock(ctrl);
4338 mutex_lock(main_hdl->lock);
4339 WARN_ON(!hdl->request_is_queued);
4340 list_del_init(&hdl->requests_queued);
4341 hdl->request_is_queued = false;
4342 mutex_unlock(main_hdl->lock);
4343 media_request_object_complete(obj);
4344 media_request_object_put(obj);
4346 EXPORT_SYMBOL(v4l2_ctrl_request_complete);
4348 int v4l2_ctrl_request_setup(struct media_request *req,
4349 struct v4l2_ctrl_handler *main_hdl)
4351 struct media_request_object *obj;
4352 struct v4l2_ctrl_handler *hdl;
4353 struct v4l2_ctrl_ref *ref;
4356 if (!req || !main_hdl)
4359 if (WARN_ON(req->state != MEDIA_REQUEST_STATE_QUEUED))
4363 * Note that it is valid if nothing was found. It means
4364 * that this request doesn't have any controls and so just
4365 * wants to leave the controls unchanged.
4367 obj = media_request_object_find(req, &req_ops, main_hdl);
4370 if (obj->completed) {
4371 media_request_object_put(obj);
4374 hdl = container_of(obj, struct v4l2_ctrl_handler, req_obj);
4376 list_for_each_entry(ref, &hdl->ctrl_refs, node)
4377 ref->req_done = false;
4379 list_for_each_entry(ref, &hdl->ctrl_refs, node) {
4380 struct v4l2_ctrl *ctrl = ref->ctrl;
4381 struct v4l2_ctrl *master = ctrl->cluster[0];
4382 bool have_new_data = false;
4386 * Skip if this control was already handled by a cluster.
4387 * Skip button controls and read-only controls.
4389 if (ref->req_done || ctrl->type == V4L2_CTRL_TYPE_BUTTON ||
4390 (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY))
4393 v4l2_ctrl_lock(master);
4394 for (i = 0; i < master->ncontrols; i++) {
4395 if (master->cluster[i]) {
4396 struct v4l2_ctrl_ref *r =
4397 find_ref(hdl, master->cluster[i]->id);
4399 if (r->req && r == r->req) {
4400 have_new_data = true;
4405 if (!have_new_data) {
4406 v4l2_ctrl_unlock(master);
4410 for (i = 0; i < master->ncontrols; i++) {
4411 if (master->cluster[i]) {
4412 struct v4l2_ctrl_ref *r =
4413 find_ref(hdl, master->cluster[i]->id);
4416 master->cluster[i]->is_new = 1;
4421 * For volatile autoclusters that are currently in auto mode
4422 * we need to discover if it will be set to manual mode.
4423 * If so, then we have to copy the current volatile values
4424 * first since those will become the new manual values (which
4425 * may be overwritten by explicit new values from this set
4428 if (master->is_auto && master->has_volatiles &&
4429 !is_cur_manual(master)) {
4430 s32 new_auto_val = *master->p_new.p_s32;
4433 * If the new value == the manual value, then copy
4434 * the current volatile values.
4436 if (new_auto_val == master->manual_mode_value)
4437 update_from_auto_cluster(master);
4440 ret = try_or_set_cluster(NULL, master, true, 0);
4441 v4l2_ctrl_unlock(master);
4447 media_request_object_put(obj);
4450 EXPORT_SYMBOL(v4l2_ctrl_request_setup);
4452 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv)
4456 if (notify == NULL) {
4457 ctrl->call_notify = 0;
4460 if (WARN_ON(ctrl->handler->notify && ctrl->handler->notify != notify))
4462 ctrl->handler->notify = notify;
4463 ctrl->handler->notify_priv = priv;
4464 ctrl->call_notify = 1;
4466 EXPORT_SYMBOL(v4l2_ctrl_notify);
4468 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
4469 s64 min, s64 max, u64 step, s64 def)
4472 bool range_changed = false;
4475 lockdep_assert_held(ctrl->handler->lock);
4477 switch (ctrl->type) {
4478 case V4L2_CTRL_TYPE_INTEGER:
4479 case V4L2_CTRL_TYPE_INTEGER64:
4480 case V4L2_CTRL_TYPE_BOOLEAN:
4481 case V4L2_CTRL_TYPE_MENU:
4482 case V4L2_CTRL_TYPE_INTEGER_MENU:
4483 case V4L2_CTRL_TYPE_BITMASK:
4484 case V4L2_CTRL_TYPE_U8:
4485 case V4L2_CTRL_TYPE_U16:
4486 case V4L2_CTRL_TYPE_U32:
4489 ret = check_range(ctrl->type, min, max, step, def);
4496 if ((ctrl->minimum != min) || (ctrl->maximum != max) ||
4497 (ctrl->step != step) || ctrl->default_value != def) {
4498 range_changed = true;
4499 ctrl->minimum = min;
4500 ctrl->maximum = max;
4502 ctrl->default_value = def;
4505 if (validate_new(ctrl, ctrl->p_new)) {
4506 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
4507 *ctrl->p_new.p_s64 = def;
4509 *ctrl->p_new.p_s32 = def;
4512 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
4513 value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64;
4515 value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32;
4517 ret = set_ctrl(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
4518 else if (range_changed)
4519 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
4522 EXPORT_SYMBOL(__v4l2_ctrl_modify_range);
4524 static int v4l2_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems)
4526 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id);
4531 v4l2_ctrl_lock(ctrl);
4532 list_add_tail(&sev->node, &ctrl->ev_subs);
4533 if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS &&
4534 (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) {
4535 struct v4l2_event ev;
4536 u32 changes = V4L2_EVENT_CTRL_CH_FLAGS;
4538 if (!(ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY))
4539 changes |= V4L2_EVENT_CTRL_CH_VALUE;
4540 fill_event(&ev, ctrl, changes);
4541 /* Mark the queue as active, allowing this initial
4542 event to be accepted. */
4544 v4l2_event_queue_fh(sev->fh, &ev);
4546 v4l2_ctrl_unlock(ctrl);
4550 static void v4l2_ctrl_del_event(struct v4l2_subscribed_event *sev)
4552 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id);
4557 v4l2_ctrl_lock(ctrl);
4558 list_del(&sev->node);
4559 v4l2_ctrl_unlock(ctrl);
4562 void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new)
4564 u32 old_changes = old->u.ctrl.changes;
4566 old->u.ctrl = new->u.ctrl;
4567 old->u.ctrl.changes |= old_changes;
4569 EXPORT_SYMBOL(v4l2_ctrl_replace);
4571 void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new)
4573 new->u.ctrl.changes |= old->u.ctrl.changes;
4575 EXPORT_SYMBOL(v4l2_ctrl_merge);
4577 const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops = {
4578 .add = v4l2_ctrl_add_event,
4579 .del = v4l2_ctrl_del_event,
4580 .replace = v4l2_ctrl_replace,
4581 .merge = v4l2_ctrl_merge,
4583 EXPORT_SYMBOL(v4l2_ctrl_sub_ev_ops);
4585 int v4l2_ctrl_log_status(struct file *file, void *fh)
4587 struct video_device *vfd = video_devdata(file);
4588 struct v4l2_fh *vfh = file->private_data;
4590 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) && vfd->v4l2_dev)
4591 v4l2_ctrl_handler_log_status(vfh->ctrl_handler,
4592 vfd->v4l2_dev->name);
4595 EXPORT_SYMBOL(v4l2_ctrl_log_status);
4597 int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
4598 const struct v4l2_event_subscription *sub)
4600 if (sub->type == V4L2_EVENT_CTRL)
4601 return v4l2_event_subscribe(fh, sub, 0, &v4l2_ctrl_sub_ev_ops);
4604 EXPORT_SYMBOL(v4l2_ctrl_subscribe_event);
4606 int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
4607 struct v4l2_event_subscription *sub)
4609 if (!sd->ctrl_handler)
4611 return v4l2_ctrl_subscribe_event(fh, sub);
4613 EXPORT_SYMBOL(v4l2_ctrl_subdev_subscribe_event);
4615 __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait)
4617 struct v4l2_fh *fh = file->private_data;
4619 poll_wait(file, &fh->wait, wait);
4620 if (v4l2_event_pending(fh))
4624 EXPORT_SYMBOL(v4l2_ctrl_poll);
4626 int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
4627 const struct v4l2_ctrl_ops *ctrl_ops,
4628 const struct v4l2_fwnode_device_properties *p)
4630 if (p->orientation != V4L2_FWNODE_PROPERTY_UNSET) {
4631 u32 orientation_ctrl;
4633 switch (p->orientation) {
4634 case V4L2_FWNODE_ORIENTATION_FRONT:
4635 orientation_ctrl = V4L2_CAMERA_ORIENTATION_FRONT;
4637 case V4L2_FWNODE_ORIENTATION_BACK:
4638 orientation_ctrl = V4L2_CAMERA_ORIENTATION_BACK;
4640 case V4L2_FWNODE_ORIENTATION_EXTERNAL:
4641 orientation_ctrl = V4L2_CAMERA_ORIENTATION_EXTERNAL;
4646 if (!v4l2_ctrl_new_std_menu(hdl, ctrl_ops,
4647 V4L2_CID_CAMERA_ORIENTATION,
4648 V4L2_CAMERA_ORIENTATION_EXTERNAL, 0,
4653 if (p->rotation != V4L2_FWNODE_PROPERTY_UNSET) {
4654 if (!v4l2_ctrl_new_std(hdl, ctrl_ops,
4655 V4L2_CID_CAMERA_SENSOR_ROTATION,
4656 p->rotation, p->rotation, 1,
4663 EXPORT_SYMBOL(v4l2_ctrl_new_fwnode_properties);