LCOV - code coverage report
Current view: top level - drivers/media/v4l2-core - v4l2-ctrls.c (source / functions) Hit Total Coverage
Test: Real Lines: 276 1784 15.5 %
Date: 2020-10-17 15:46:16 Functions: 0 93 0.0 %
Legend: Neither, QEMU, Real, Both Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0-or-later
       2                 :            : /*
       3                 :            :     V4L2 controls framework implementation.
       4                 :            : 
       5                 :            :     Copyright (C) 2010  Hans Verkuil <hverkuil@xs4all.nl>
       6                 :            : 
       7                 :            :  */
       8                 :            : 
       9                 :            : #define pr_fmt(fmt) "v4l2-ctrls: " fmt
      10                 :            : 
      11                 :            : #include <linux/ctype.h>
      12                 :            : #include <linux/mm.h>
      13                 :            : #include <linux/slab.h>
      14                 :            : #include <linux/export.h>
      15                 :            : #include <media/v4l2-ioctl.h>
      16                 :            : #include <media/v4l2-device.h>
      17                 :            : #include <media/v4l2-ctrls.h>
      18                 :            : #include <media/v4l2-event.h>
      19                 :            : #include <media/v4l2-dev.h>
      20                 :            : #include <media/v4l2-fwnode.h>
      21                 :            : 
      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);  \
      26                 :            : } while (0)
      27                 :            : 
      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)
      32                 :            : 
      33                 :            : /* Internal temporary helper struct, one for each v4l2_ext_control */
      34                 :            : struct v4l2_ctrl_helper {
      35                 :            :         /* Pointer to the control reference of the master control */
      36                 :            :         struct v4l2_ctrl_ref *mref;
      37                 :            :         /* The control ref corresponding to the v4l2_ext_control ID field. */
      38                 :            :         struct v4l2_ctrl_ref *ref;
      39                 :            :         /* v4l2_ext_control index of the next control belonging to the
      40                 :            :            same cluster, or 0 if there isn't any. */
      41                 :            :         u32 next;
      42                 :            : };
      43                 :            : 
      44                 :            : /* Small helper function to determine if the autocluster is set to manual
      45                 :            :    mode. */
      46                 :            : static bool is_cur_manual(const struct v4l2_ctrl *master)
      47                 :            : {
      48                 :          0 :         return master->is_auto && master->cur.val == master->manual_mode_value;
      49                 :            : }
      50                 :            : 
      51                 :            : /* Same as above, but this checks the against the new value instead of the
      52                 :            :    current value. */
      53                 :            : static bool is_new_manual(const struct v4l2_ctrl *master)
      54                 :            : {
      55                 :          0 :         return master->is_auto && master->val == master->manual_mode_value;
      56                 :            : }
      57                 :            : 
      58                 :            : /* Returns NULL or a character pointer array containing the menu for
      59                 :            :    the given control ID. The pointer array ends with a NULL pointer.
      60                 :            :    An empty string signifies a menu entry that is invalid. This allows
      61                 :            :    drivers to disable certain options if it is not supported. */
      62                 :          3 : const char * const *v4l2_ctrl_get_menu(u32 id)
      63                 :            : {
      64                 :            :         static const char * const mpeg_audio_sampling_freq[] = {
      65                 :            :                 "44.1 kHz",
      66                 :            :                 "48 kHz",
      67                 :            :                 "32 kHz",
      68                 :            :                 NULL
      69                 :            :         };
      70                 :            :         static const char * const mpeg_audio_encoding[] = {
      71                 :            :                 "MPEG-1/2 Layer I",
      72                 :            :                 "MPEG-1/2 Layer II",
      73                 :            :                 "MPEG-1/2 Layer III",
      74                 :            :                 "MPEG-2/4 AAC",
      75                 :            :                 "AC-3",
      76                 :            :                 NULL
      77                 :            :         };
      78                 :            :         static const char * const mpeg_audio_l1_bitrate[] = {
      79                 :            :                 "32 kbps",
      80                 :            :                 "64 kbps",
      81                 :            :                 "96 kbps",
      82                 :            :                 "128 kbps",
      83                 :            :                 "160 kbps",
      84                 :            :                 "192 kbps",
      85                 :            :                 "224 kbps",
      86                 :            :                 "256 kbps",
      87                 :            :                 "288 kbps",
      88                 :            :                 "320 kbps",
      89                 :            :                 "352 kbps",
      90                 :            :                 "384 kbps",
      91                 :            :                 "416 kbps",
      92                 :            :                 "448 kbps",
      93                 :            :                 NULL
      94                 :            :         };
      95                 :            :         static const char * const mpeg_audio_l2_bitrate[] = {
      96                 :            :                 "32 kbps",
      97                 :            :                 "48 kbps",
      98                 :            :                 "56 kbps",
      99                 :            :                 "64 kbps",
     100                 :            :                 "80 kbps",
     101                 :            :                 "96 kbps",
     102                 :            :                 "112 kbps",
     103                 :            :                 "128 kbps",
     104                 :            :                 "160 kbps",
     105                 :            :                 "192 kbps",
     106                 :            :                 "224 kbps",
     107                 :            :                 "256 kbps",
     108                 :            :                 "320 kbps",
     109                 :            :                 "384 kbps",
     110                 :            :                 NULL
     111                 :            :         };
     112                 :            :         static const char * const mpeg_audio_l3_bitrate[] = {
     113                 :            :                 "32 kbps",
     114                 :            :                 "40 kbps",
     115                 :            :                 "48 kbps",
     116                 :            :                 "56 kbps",
     117                 :            :                 "64 kbps",
     118                 :            :                 "80 kbps",
     119                 :            :                 "96 kbps",
     120                 :            :                 "112 kbps",
     121                 :            :                 "128 kbps",
     122                 :            :                 "160 kbps",
     123                 :            :                 "192 kbps",
     124                 :            :                 "224 kbps",
     125                 :            :                 "256 kbps",
     126                 :            :                 "320 kbps",
     127                 :            :                 NULL
     128                 :            :         };
     129                 :            :         static const char * const mpeg_audio_ac3_bitrate[] = {
     130                 :            :                 "32 kbps",
     131                 :            :                 "40 kbps",
     132                 :            :                 "48 kbps",
     133                 :            :                 "56 kbps",
     134                 :            :                 "64 kbps",
     135                 :            :                 "80 kbps",
     136                 :            :                 "96 kbps",
     137                 :            :                 "112 kbps",
     138                 :            :                 "128 kbps",
     139                 :            :                 "160 kbps",
     140                 :            :                 "192 kbps",
     141                 :            :                 "224 kbps",
     142                 :            :                 "256 kbps",
     143                 :            :                 "320 kbps",
     144                 :            :                 "384 kbps",
     145                 :            :                 "448 kbps",
     146                 :            :                 "512 kbps",
     147                 :            :                 "576 kbps",
     148                 :            :                 "640 kbps",
     149                 :            :                 NULL
     150                 :            :         };
     151                 :            :         static const char * const mpeg_audio_mode[] = {
     152                 :            :                 "Stereo",
     153                 :            :                 "Joint Stereo",
     154                 :            :                 "Dual",
     155                 :            :                 "Mono",
     156                 :            :                 NULL
     157                 :            :         };
     158                 :            :         static const char * const mpeg_audio_mode_extension[] = {
     159                 :            :                 "Bound 4",
     160                 :            :                 "Bound 8",
     161                 :            :                 "Bound 12",
     162                 :            :                 "Bound 16",
     163                 :            :                 NULL
     164                 :            :         };
     165                 :            :         static const char * const mpeg_audio_emphasis[] = {
     166                 :            :                 "No Emphasis",
     167                 :            :                 "50/15 us",
     168                 :            :                 "CCITT J17",
     169                 :            :                 NULL
     170                 :            :         };
     171                 :            :         static const char * const mpeg_audio_crc[] = {
     172                 :            :                 "No CRC",
     173                 :            :                 "16-bit CRC",
     174                 :            :                 NULL
     175                 :            :         };
     176                 :            :         static const char * const mpeg_audio_dec_playback[] = {
     177                 :            :                 "Auto",
     178                 :            :                 "Stereo",
     179                 :            :                 "Left",
     180                 :            :                 "Right",
     181                 :            :                 "Mono",
     182                 :            :                 "Swapped Stereo",
     183                 :            :                 NULL
     184                 :            :         };
     185                 :            :         static const char * const mpeg_video_encoding[] = {
     186                 :            :                 "MPEG-1",
     187                 :            :                 "MPEG-2",
     188                 :            :                 "MPEG-4 AVC",
     189                 :            :                 NULL
     190                 :            :         };
     191                 :            :         static const char * const mpeg_video_aspect[] = {
     192                 :            :                 "1x1",
     193                 :            :                 "4x3",
     194                 :            :                 "16x9",
     195                 :            :                 "2.21x1",
     196                 :            :                 NULL
     197                 :            :         };
     198                 :            :         static const char * const mpeg_video_bitrate_mode[] = {
     199                 :            :                 "Variable Bitrate",
     200                 :            :                 "Constant Bitrate",
     201                 :            :                 NULL
     202                 :            :         };
     203                 :            :         static const char * const mpeg_stream_type[] = {
     204                 :            :                 "MPEG-2 Program Stream",
     205                 :            :                 "MPEG-2 Transport Stream",
     206                 :            :                 "MPEG-1 System Stream",
     207                 :            :                 "MPEG-2 DVD-compatible Stream",
     208                 :            :                 "MPEG-1 VCD-compatible Stream",
     209                 :            :                 "MPEG-2 SVCD-compatible Stream",
     210                 :            :                 NULL
     211                 :            :         };
     212                 :            :         static const char * const mpeg_stream_vbi_fmt[] = {
     213                 :            :                 "No VBI",
     214                 :            :                 "Private Packet, IVTV Format",
     215                 :            :                 NULL
     216                 :            :         };
     217                 :            :         static const char * const camera_power_line_frequency[] = {
     218                 :            :                 "Disabled",
     219                 :            :                 "50 Hz",
     220                 :            :                 "60 Hz",
     221                 :            :                 "Auto",
     222                 :            :                 NULL
     223                 :            :         };
     224                 :            :         static const char * const camera_exposure_auto[] = {
     225                 :            :                 "Auto Mode",
     226                 :            :                 "Manual Mode",
     227                 :            :                 "Shutter Priority Mode",
     228                 :            :                 "Aperture Priority Mode",
     229                 :            :                 NULL
     230                 :            :         };
     231                 :            :         static const char * const camera_exposure_metering[] = {
     232                 :            :                 "Average",
     233                 :            :                 "Center Weighted",
     234                 :            :                 "Spot",
     235                 :            :                 "Matrix",
     236                 :            :                 NULL
     237                 :            :         };
     238                 :            :         static const char * const camera_auto_focus_range[] = {
     239                 :            :                 "Auto",
     240                 :            :                 "Normal",
     241                 :            :                 "Macro",
     242                 :            :                 "Infinity",
     243                 :            :                 NULL
     244                 :            :         };
     245                 :            :         static const char * const colorfx[] = {
     246                 :            :                 "None",
     247                 :            :                 "Black & White",
     248                 :            :                 "Sepia",
     249                 :            :                 "Negative",
     250                 :            :                 "Emboss",
     251                 :            :                 "Sketch",
     252                 :            :                 "Sky Blue",
     253                 :            :                 "Grass Green",
     254                 :            :                 "Skin Whiten",
     255                 :            :                 "Vivid",
     256                 :            :                 "Aqua",
     257                 :            :                 "Art Freeze",
     258                 :            :                 "Silhouette",
     259                 :            :                 "Solarization",
     260                 :            :                 "Antique",
     261                 :            :                 "Set Cb/Cr",
     262                 :            :                 NULL
     263                 :            :         };
     264                 :            :         static const char * const auto_n_preset_white_balance[] = {
     265                 :            :                 "Manual",
     266                 :            :                 "Auto",
     267                 :            :                 "Incandescent",
     268                 :            :                 "Fluorescent",
     269                 :            :                 "Fluorescent H",
     270                 :            :                 "Horizon",
     271                 :            :                 "Daylight",
     272                 :            :                 "Flash",
     273                 :            :                 "Cloudy",
     274                 :            :                 "Shade",
     275                 :            :                 "Greyworld",
     276                 :            :                 NULL,
     277                 :            :         };
     278                 :            :         static const char * const camera_iso_sensitivity_auto[] = {
     279                 :            :                 "Manual",
     280                 :            :                 "Auto",
     281                 :            :                 NULL
     282                 :            :         };
     283                 :            :         static const char * const scene_mode[] = {
     284                 :            :                 "None",
     285                 :            :                 "Backlight",
     286                 :            :                 "Beach/Snow",
     287                 :            :                 "Candle Light",
     288                 :            :                 "Dusk/Dawn",
     289                 :            :                 "Fall Colors",
     290                 :            :                 "Fireworks",
     291                 :            :                 "Landscape",
     292                 :            :                 "Night",
     293                 :            :                 "Party/Indoor",
     294                 :            :                 "Portrait",
     295                 :            :                 "Sports",
     296                 :            :                 "Sunset",
     297                 :            :                 "Text",
     298                 :            :                 NULL
     299                 :            :         };
     300                 :            :         static const char * const tune_emphasis[] = {
     301                 :            :                 "None",
     302                 :            :                 "50 Microseconds",
     303                 :            :                 "75 Microseconds",
     304                 :            :                 NULL,
     305                 :            :         };
     306                 :            :         static const char * const header_mode[] = {
     307                 :            :                 "Separate Buffer",
     308                 :            :                 "Joined With 1st Frame",
     309                 :            :                 NULL,
     310                 :            :         };
     311                 :            :         static const char * const multi_slice[] = {
     312                 :            :                 "Single",
     313                 :            :                 "Max Macroblocks",
     314                 :            :                 "Max Bytes",
     315                 :            :                 NULL,
     316                 :            :         };
     317                 :            :         static const char * const entropy_mode[] = {
     318                 :            :                 "CAVLC",
     319                 :            :                 "CABAC",
     320                 :            :                 NULL,
     321                 :            :         };
     322                 :            :         static const char * const mpeg_h264_level[] = {
     323                 :            :                 "1",
     324                 :            :                 "1b",
     325                 :            :                 "1.1",
     326                 :            :                 "1.2",
     327                 :            :                 "1.3",
     328                 :            :                 "2",
     329                 :            :                 "2.1",
     330                 :            :                 "2.2",
     331                 :            :                 "3",
     332                 :            :                 "3.1",
     333                 :            :                 "3.2",
     334                 :            :                 "4",
     335                 :            :                 "4.1",
     336                 :            :                 "4.2",
     337                 :            :                 "5",
     338                 :            :                 "5.1",
     339                 :            :                 NULL,
     340                 :            :         };
     341                 :            :         static const char * const h264_loop_filter[] = {
     342                 :            :                 "Enabled",
     343                 :            :                 "Disabled",
     344                 :            :                 "Disabled at Slice Boundary",
     345                 :            :                 NULL,
     346                 :            :         };
     347                 :            :         static const char * const h264_profile[] = {
     348                 :            :                 "Baseline",
     349                 :            :                 "Constrained Baseline",
     350                 :            :                 "Main",
     351                 :            :                 "Extended",
     352                 :            :                 "High",
     353                 :            :                 "High 10",
     354                 :            :                 "High 422",
     355                 :            :                 "High 444 Predictive",
     356                 :            :                 "High 10 Intra",
     357                 :            :                 "High 422 Intra",
     358                 :            :                 "High 444 Intra",
     359                 :            :                 "CAVLC 444 Intra",
     360                 :            :                 "Scalable Baseline",
     361                 :            :                 "Scalable High",
     362                 :            :                 "Scalable High Intra",
     363                 :            :                 "Stereo High",
     364                 :            :                 "Multiview High",
     365                 :            :                 NULL,
     366                 :            :         };
     367                 :            :         static const char * const vui_sar_idc[] = {
     368                 :            :                 "Unspecified",
     369                 :            :                 "1:1",
     370                 :            :                 "12:11",
     371                 :            :                 "10:11",
     372                 :            :                 "16:11",
     373                 :            :                 "40:33",
     374                 :            :                 "24:11",
     375                 :            :                 "20:11",
     376                 :            :                 "32:11",
     377                 :            :                 "80:33",
     378                 :            :                 "18:11",
     379                 :            :                 "15:11",
     380                 :            :                 "64:33",
     381                 :            :                 "160:99",
     382                 :            :                 "4:3",
     383                 :            :                 "3:2",
     384                 :            :                 "2:1",
     385                 :            :                 "Extended SAR",
     386                 :            :                 NULL,
     387                 :            :         };
     388                 :            :         static const char * const h264_fp_arrangement_type[] = {
     389                 :            :                 "Checkerboard",
     390                 :            :                 "Column",
     391                 :            :                 "Row",
     392                 :            :                 "Side by Side",
     393                 :            :                 "Top Bottom",
     394                 :            :                 "Temporal",
     395                 :            :                 NULL,
     396                 :            :         };
     397                 :            :         static const char * const h264_fmo_map_type[] = {
     398                 :            :                 "Interleaved Slices",
     399                 :            :                 "Scattered Slices",
     400                 :            :                 "Foreground with Leftover",
     401                 :            :                 "Box Out",
     402                 :            :                 "Raster Scan",
     403                 :            :                 "Wipe Scan",
     404                 :            :                 "Explicit",
     405                 :            :                 NULL,
     406                 :            :         };
     407                 :            :         static const char * const h264_decode_mode[] = {
     408                 :            :                 "Slice-Based",
     409                 :            :                 "Frame-Based",
     410                 :            :                 NULL,
     411                 :            :         };
     412                 :            :         static const char * const h264_start_code[] = {
     413                 :            :                 "No Start Code",
     414                 :            :                 "Annex B Start Code",
     415                 :            :                 NULL,
     416                 :            :         };
     417                 :            :         static const char * const mpeg_mpeg2_level[] = {
     418                 :            :                 "Low",
     419                 :            :                 "Main",
     420                 :            :                 "High 1440",
     421                 :            :                 "High",
     422                 :            :                 NULL,
     423                 :            :         };
     424                 :            :         static const char * const mpeg2_profile[] = {
     425                 :            :                 "Simple",
     426                 :            :                 "Main",
     427                 :            :                 "SNR Scalable",
     428                 :            :                 "Spatially Scalable",
     429                 :            :                 "High",
     430                 :            :                 NULL,
     431                 :            :         };
     432                 :            :         static const char * const mpeg_mpeg4_level[] = {
     433                 :            :                 "0",
     434                 :            :                 "0b",
     435                 :            :                 "1",
     436                 :            :                 "2",
     437                 :            :                 "3",
     438                 :            :                 "3b",
     439                 :            :                 "4",
     440                 :            :                 "5",
     441                 :            :                 NULL,
     442                 :            :         };
     443                 :            :         static const char * const mpeg4_profile[] = {
     444                 :            :                 "Simple",
     445                 :            :                 "Advanced Simple",
     446                 :            :                 "Core",
     447                 :            :                 "Simple Scalable",
     448                 :            :                 "Advanced Coding Efficiency",
     449                 :            :                 NULL,
     450                 :            :         };
     451                 :            : 
     452                 :            :         static const char * const vpx_golden_frame_sel[] = {
     453                 :            :                 "Use Previous Frame",
     454                 :            :                 "Use Previous Specific Frame",
     455                 :            :                 NULL,
     456                 :            :         };
     457                 :            :         static const char * const vp8_profile[] = {
     458                 :            :                 "0",
     459                 :            :                 "1",
     460                 :            :                 "2",
     461                 :            :                 "3",
     462                 :            :                 NULL,
     463                 :            :         };
     464                 :            :         static const char * const vp9_profile[] = {
     465                 :            :                 "0",
     466                 :            :                 "1",
     467                 :            :                 "2",
     468                 :            :                 "3",
     469                 :            :                 NULL,
     470                 :            :         };
     471                 :            : 
     472                 :            :         static const char * const flash_led_mode[] = {
     473                 :            :                 "Off",
     474                 :            :                 "Flash",
     475                 :            :                 "Torch",
     476                 :            :                 NULL,
     477                 :            :         };
     478                 :            :         static const char * const flash_strobe_source[] = {
     479                 :            :                 "Software",
     480                 :            :                 "External",
     481                 :            :                 NULL,
     482                 :            :         };
     483                 :            : 
     484                 :            :         static const char * const jpeg_chroma_subsampling[] = {
     485                 :            :                 "4:4:4",
     486                 :            :                 "4:2:2",
     487                 :            :                 "4:2:0",
     488                 :            :                 "4:1:1",
     489                 :            :                 "4:1:0",
     490                 :            :                 "Gray",
     491                 :            :                 NULL,
     492                 :            :         };
     493                 :            :         static const char * const dv_tx_mode[] = {
     494                 :            :                 "DVI-D",
     495                 :            :                 "HDMI",
     496                 :            :                 NULL,
     497                 :            :         };
     498                 :            :         static const char * const dv_rgb_range[] = {
     499                 :            :                 "Automatic",
     500                 :            :                 "RGB Limited Range (16-235)",
     501                 :            :                 "RGB Full Range (0-255)",
     502                 :            :                 NULL,
     503                 :            :         };
     504                 :            :         static const char * const dv_it_content_type[] = {
     505                 :            :                 "Graphics",
     506                 :            :                 "Photo",
     507                 :            :                 "Cinema",
     508                 :            :                 "Game",
     509                 :            :                 "No IT Content",
     510                 :            :                 NULL,
     511                 :            :         };
     512                 :            :         static const char * const detect_md_mode[] = {
     513                 :            :                 "Disabled",
     514                 :            :                 "Global",
     515                 :            :                 "Threshold Grid",
     516                 :            :                 "Region Grid",
     517                 :            :                 NULL,
     518                 :            :         };
     519                 :            : 
     520                 :            :         static const char * const hevc_profile[] = {
     521                 :            :                 "Main",
     522                 :            :                 "Main Still Picture",
     523                 :            :                 "Main 10",
     524                 :            :                 NULL,
     525                 :            :         };
     526                 :            :         static const char * const hevc_level[] = {
     527                 :            :                 "1",
     528                 :            :                 "2",
     529                 :            :                 "2.1",
     530                 :            :                 "3",
     531                 :            :                 "3.1",
     532                 :            :                 "4",
     533                 :            :                 "4.1",
     534                 :            :                 "5",
     535                 :            :                 "5.1",
     536                 :            :                 "5.2",
     537                 :            :                 "6",
     538                 :            :                 "6.1",
     539                 :            :                 "6.2",
     540                 :            :                 NULL,
     541                 :            :         };
     542                 :            :         static const char * const hevc_hierarchial_coding_type[] = {
     543                 :            :                 "B",
     544                 :            :                 "P",
     545                 :            :                 NULL,
     546                 :            :         };
     547                 :            :         static const char * const hevc_refresh_type[] = {
     548                 :            :                 "None",
     549                 :            :                 "CRA",
     550                 :            :                 "IDR",
     551                 :            :                 NULL,
     552                 :            :         };
     553                 :            :         static const char * const hevc_size_of_length_field[] = {
     554                 :            :                 "0",
     555                 :            :                 "1",
     556                 :            :                 "2",
     557                 :            :                 "4",
     558                 :            :                 NULL,
     559                 :            :         };
     560                 :            :         static const char * const hevc_tier[] = {
     561                 :            :                 "Main",
     562                 :            :                 "High",
     563                 :            :                 NULL,
     564                 :            :         };
     565                 :            :         static const char * const hevc_loop_filter_mode[] = {
     566                 :            :                 "Disabled",
     567                 :            :                 "Enabled",
     568                 :            :                 "Disabled at slice boundary",
     569                 :            :                 "NULL",
     570                 :            :         };
     571                 :            :         static const char * const hevc_decode_mode[] = {
     572                 :            :                 "Slice-Based",
     573                 :            :                 "Frame-Based",
     574                 :            :                 NULL,
     575                 :            :         };
     576                 :            :         static const char * const hevc_start_code[] = {
     577                 :            :                 "No Start Code",
     578                 :            :                 "Annex B Start Code",
     579                 :            :                 NULL,
     580                 :            :         };
     581                 :            :         static const char * const camera_orientation[] = {
     582                 :            :                 "Front",
     583                 :            :                 "Back",
     584                 :            :                 "External",
     585                 :            :                 NULL,
     586                 :            :         };
     587                 :            : 
     588                 :          3 :         switch (id) {
     589                 :            :         case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
     590                 :            :                 return mpeg_audio_sampling_freq;
     591                 :            :         case V4L2_CID_MPEG_AUDIO_ENCODING:
     592                 :          0 :                 return mpeg_audio_encoding;
     593                 :            :         case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
     594                 :          0 :                 return mpeg_audio_l1_bitrate;
     595                 :            :         case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
     596                 :          0 :                 return mpeg_audio_l2_bitrate;
     597                 :            :         case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
     598                 :          0 :                 return mpeg_audio_l3_bitrate;
     599                 :            :         case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
     600                 :          0 :                 return mpeg_audio_ac3_bitrate;
     601                 :            :         case V4L2_CID_MPEG_AUDIO_MODE:
     602                 :          0 :                 return mpeg_audio_mode;
     603                 :            :         case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
     604                 :          0 :                 return mpeg_audio_mode_extension;
     605                 :            :         case V4L2_CID_MPEG_AUDIO_EMPHASIS:
     606                 :          0 :                 return mpeg_audio_emphasis;
     607                 :            :         case V4L2_CID_MPEG_AUDIO_CRC:
     608                 :          0 :                 return mpeg_audio_crc;
     609                 :            :         case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK:
     610                 :            :         case V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK:
     611                 :          0 :                 return mpeg_audio_dec_playback;
     612                 :            :         case V4L2_CID_MPEG_VIDEO_ENCODING:
     613                 :          0 :                 return mpeg_video_encoding;
     614                 :            :         case V4L2_CID_MPEG_VIDEO_ASPECT:
     615                 :          0 :                 return mpeg_video_aspect;
     616                 :            :         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
     617                 :          3 :                 return mpeg_video_bitrate_mode;
     618                 :            :         case V4L2_CID_MPEG_STREAM_TYPE:
     619                 :          0 :                 return mpeg_stream_type;
     620                 :            :         case V4L2_CID_MPEG_STREAM_VBI_FMT:
     621                 :          0 :                 return mpeg_stream_vbi_fmt;
     622                 :            :         case V4L2_CID_POWER_LINE_FREQUENCY:
     623                 :          0 :                 return camera_power_line_frequency;
     624                 :            :         case V4L2_CID_EXPOSURE_AUTO:
     625                 :          0 :                 return camera_exposure_auto;
     626                 :            :         case V4L2_CID_EXPOSURE_METERING:
     627                 :          0 :                 return camera_exposure_metering;
     628                 :            :         case V4L2_CID_AUTO_FOCUS_RANGE:
     629                 :          0 :                 return camera_auto_focus_range;
     630                 :            :         case V4L2_CID_COLORFX:
     631                 :          0 :                 return colorfx;
     632                 :            :         case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
     633                 :          0 :                 return auto_n_preset_white_balance;
     634                 :            :         case V4L2_CID_ISO_SENSITIVITY_AUTO:
     635                 :          0 :                 return camera_iso_sensitivity_auto;
     636                 :            :         case V4L2_CID_SCENE_MODE:
     637                 :          0 :                 return scene_mode;
     638                 :            :         case V4L2_CID_TUNE_PREEMPHASIS:
     639                 :          0 :                 return tune_emphasis;
     640                 :            :         case V4L2_CID_TUNE_DEEMPHASIS:
     641                 :          0 :                 return tune_emphasis;
     642                 :            :         case V4L2_CID_FLASH_LED_MODE:
     643                 :          0 :                 return flash_led_mode;
     644                 :            :         case V4L2_CID_FLASH_STROBE_SOURCE:
     645                 :          0 :                 return flash_strobe_source;
     646                 :            :         case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
     647                 :          0 :                 return header_mode;
     648                 :            :         case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
     649                 :          0 :                 return multi_slice;
     650                 :            :         case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
     651                 :          0 :                 return entropy_mode;
     652                 :            :         case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
     653                 :          3 :                 return mpeg_h264_level;
     654                 :            :         case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
     655                 :          0 :                 return h264_loop_filter;
     656                 :            :         case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
     657                 :          3 :                 return h264_profile;
     658                 :            :         case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC:
     659                 :          0 :                 return vui_sar_idc;
     660                 :            :         case V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE:
     661                 :          0 :                 return h264_fp_arrangement_type;
     662                 :            :         case V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE:
     663                 :          0 :                 return h264_fmo_map_type;
     664                 :            :         case V4L2_CID_MPEG_VIDEO_H264_DECODE_MODE:
     665                 :          0 :                 return h264_decode_mode;
     666                 :            :         case V4L2_CID_MPEG_VIDEO_H264_START_CODE:
     667                 :          0 :                 return h264_start_code;
     668                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL:
     669                 :          0 :                 return mpeg_mpeg2_level;
     670                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE:
     671                 :          0 :                 return mpeg2_profile;
     672                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
     673                 :          0 :                 return mpeg_mpeg4_level;
     674                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
     675                 :          0 :                 return mpeg4_profile;
     676                 :            :         case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL:
     677                 :          0 :                 return vpx_golden_frame_sel;
     678                 :            :         case V4L2_CID_MPEG_VIDEO_VP8_PROFILE:
     679                 :          0 :                 return vp8_profile;
     680                 :            :         case V4L2_CID_MPEG_VIDEO_VP9_PROFILE:
     681                 :          0 :                 return vp9_profile;
     682                 :            :         case V4L2_CID_JPEG_CHROMA_SUBSAMPLING:
     683                 :          0 :                 return jpeg_chroma_subsampling;
     684                 :            :         case V4L2_CID_DV_TX_MODE:
     685                 :          0 :                 return dv_tx_mode;
     686                 :            :         case V4L2_CID_DV_TX_RGB_RANGE:
     687                 :            :         case V4L2_CID_DV_RX_RGB_RANGE:
     688                 :          0 :                 return dv_rgb_range;
     689                 :            :         case V4L2_CID_DV_TX_IT_CONTENT_TYPE:
     690                 :            :         case V4L2_CID_DV_RX_IT_CONTENT_TYPE:
     691                 :          0 :                 return dv_it_content_type;
     692                 :            :         case V4L2_CID_DETECT_MD_MODE:
     693                 :          0 :                 return detect_md_mode;
     694                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE:
     695                 :          0 :                 return hevc_profile;
     696                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL:
     697                 :          0 :                 return hevc_level;
     698                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE:
     699                 :          0 :                 return hevc_hierarchial_coding_type;
     700                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE:
     701                 :          0 :                 return hevc_refresh_type;
     702                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD:
     703                 :          0 :                 return hevc_size_of_length_field;
     704                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_TIER:
     705                 :          0 :                 return hevc_tier;
     706                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE:
     707                 :          0 :                 return hevc_loop_filter_mode;
     708                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE:
     709                 :          0 :                 return hevc_decode_mode;
     710                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE:
     711                 :          0 :                 return hevc_start_code;
     712                 :            :         case V4L2_CID_CAMERA_ORIENTATION:
     713                 :          0 :                 return camera_orientation;
     714                 :            :         default:
     715                 :          0 :                 return NULL;
     716                 :            :         }
     717                 :            : }
     718                 :            : EXPORT_SYMBOL(v4l2_ctrl_get_menu);
     719                 :            : 
     720                 :            : #define __v4l2_qmenu_int_len(arr, len) ({ *(len) = ARRAY_SIZE(arr); arr; })
     721                 :            : /*
     722                 :            :  * Returns NULL or an s64 type array containing the menu for given
     723                 :            :  * control ID. The total number of the menu items is returned in @len.
     724                 :            :  */
     725                 :          0 : const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len)
     726                 :            : {
     727                 :            :         static const s64 qmenu_int_vpx_num_partitions[] = {
     728                 :            :                 1, 2, 4, 8,
     729                 :            :         };
     730                 :            : 
     731                 :            :         static const s64 qmenu_int_vpx_num_ref_frames[] = {
     732                 :            :                 1, 2, 3,
     733                 :            :         };
     734                 :            : 
     735                 :          0 :         switch (id) {
     736                 :            :         case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS:
     737                 :          0 :                 return __v4l2_qmenu_int_len(qmenu_int_vpx_num_partitions, len);
     738                 :            :         case V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES:
     739                 :          0 :                 return __v4l2_qmenu_int_len(qmenu_int_vpx_num_ref_frames, len);
     740                 :            :         default:
     741                 :          0 :                 *len = 0;
     742                 :          0 :                 return NULL;
     743                 :            :         }
     744                 :            : }
     745                 :            : EXPORT_SYMBOL(v4l2_ctrl_get_int_menu);
     746                 :            : 
     747                 :            : /* Return the control name. */
     748                 :          3 : const char *v4l2_ctrl_get_name(u32 id)
     749                 :            : {
     750                 :          3 :         switch (id) {
     751                 :            :         /* USER controls */
     752                 :            :         /* Keep the order of the 'case's the same as in v4l2-controls.h! */
     753                 :            :         case V4L2_CID_USER_CLASS:               return "User Controls";
     754                 :          0 :         case V4L2_CID_BRIGHTNESS:               return "Brightness";
     755                 :          0 :         case V4L2_CID_CONTRAST:                 return "Contrast";
     756                 :          0 :         case V4L2_CID_SATURATION:               return "Saturation";
     757                 :          0 :         case V4L2_CID_HUE:                      return "Hue";
     758                 :          0 :         case V4L2_CID_AUDIO_VOLUME:             return "Volume";
     759                 :          0 :         case V4L2_CID_AUDIO_BALANCE:            return "Balance";
     760                 :          0 :         case V4L2_CID_AUDIO_BASS:               return "Bass";
     761                 :          0 :         case V4L2_CID_AUDIO_TREBLE:             return "Treble";
     762                 :          0 :         case V4L2_CID_AUDIO_MUTE:               return "Mute";
     763                 :          0 :         case V4L2_CID_AUDIO_LOUDNESS:           return "Loudness";
     764                 :          0 :         case V4L2_CID_BLACK_LEVEL:              return "Black Level";
     765                 :          0 :         case V4L2_CID_AUTO_WHITE_BALANCE:       return "White Balance, Automatic";
     766                 :          0 :         case V4L2_CID_DO_WHITE_BALANCE:         return "Do White Balance";
     767                 :          3 :         case V4L2_CID_RED_BALANCE:              return "Red Balance";
     768                 :          3 :         case V4L2_CID_BLUE_BALANCE:             return "Blue Balance";
     769                 :          0 :         case V4L2_CID_GAMMA:                    return "Gamma";
     770                 :          0 :         case V4L2_CID_EXPOSURE:                 return "Exposure";
     771                 :          0 :         case V4L2_CID_AUTOGAIN:                 return "Gain, Automatic";
     772                 :          0 :         case V4L2_CID_GAIN:                     return "Gain";
     773                 :          0 :         case V4L2_CID_HFLIP:                    return "Horizontal Flip";
     774                 :          0 :         case V4L2_CID_VFLIP:                    return "Vertical Flip";
     775                 :          0 :         case V4L2_CID_POWER_LINE_FREQUENCY:     return "Power Line Frequency";
     776                 :          0 :         case V4L2_CID_HUE_AUTO:                 return "Hue, Automatic";
     777                 :          0 :         case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature";
     778                 :          0 :         case V4L2_CID_SHARPNESS:                return "Sharpness";
     779                 :          0 :         case V4L2_CID_BACKLIGHT_COMPENSATION:   return "Backlight Compensation";
     780                 :          0 :         case V4L2_CID_CHROMA_AGC:               return "Chroma AGC";
     781                 :          0 :         case V4L2_CID_COLOR_KILLER:             return "Color Killer";
     782                 :          0 :         case V4L2_CID_COLORFX:                  return "Color Effects";
     783                 :          0 :         case V4L2_CID_AUTOBRIGHTNESS:           return "Brightness, Automatic";
     784                 :          0 :         case V4L2_CID_BAND_STOP_FILTER:         return "Band-Stop Filter";
     785                 :          0 :         case V4L2_CID_ROTATE:                   return "Rotate";
     786                 :          0 :         case V4L2_CID_BG_COLOR:                 return "Background Color";
     787                 :          0 :         case V4L2_CID_CHROMA_GAIN:              return "Chroma Gain";
     788                 :          0 :         case V4L2_CID_ILLUMINATORS_1:           return "Illuminator 1";
     789                 :          0 :         case V4L2_CID_ILLUMINATORS_2:           return "Illuminator 2";
     790                 :          3 :         case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:  return "Min Number of Capture Buffers";
     791                 :          0 :         case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:   return "Min Number of Output Buffers";
     792                 :          0 :         case V4L2_CID_ALPHA_COMPONENT:          return "Alpha Component";
     793                 :          0 :         case V4L2_CID_COLORFX_CBCR:             return "Color Effects, CbCr";
     794                 :            : 
     795                 :            :         /* Codec controls */
     796                 :            :         /* The MPEG controls are applicable to all codec controls
     797                 :            :          * and the 'MPEG' part of the define is historical */
     798                 :            :         /* Keep the order of the 'case's the same as in videodev2.h! */
     799                 :          3 :         case V4L2_CID_MPEG_CLASS:               return "Codec Controls";
     800                 :          0 :         case V4L2_CID_MPEG_STREAM_TYPE:         return "Stream Type";
     801                 :          0 :         case V4L2_CID_MPEG_STREAM_PID_PMT:      return "Stream PMT Program ID";
     802                 :          0 :         case V4L2_CID_MPEG_STREAM_PID_AUDIO:    return "Stream Audio Program ID";
     803                 :          0 :         case V4L2_CID_MPEG_STREAM_PID_VIDEO:    return "Stream Video Program ID";
     804                 :          0 :         case V4L2_CID_MPEG_STREAM_PID_PCR:      return "Stream PCR Program ID";
     805                 :          0 :         case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
     806                 :          0 :         case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
     807                 :          0 :         case V4L2_CID_MPEG_STREAM_VBI_FMT:      return "Stream VBI Format";
     808                 :          0 :         case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
     809                 :          0 :         case V4L2_CID_MPEG_AUDIO_ENCODING:      return "Audio Encoding";
     810                 :          0 :         case V4L2_CID_MPEG_AUDIO_L1_BITRATE:    return "Audio Layer I Bitrate";
     811                 :          0 :         case V4L2_CID_MPEG_AUDIO_L2_BITRATE:    return "Audio Layer II Bitrate";
     812                 :          0 :         case V4L2_CID_MPEG_AUDIO_L3_BITRATE:    return "Audio Layer III Bitrate";
     813                 :          0 :         case V4L2_CID_MPEG_AUDIO_MODE:          return "Audio Stereo Mode";
     814                 :          0 :         case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
     815                 :          0 :         case V4L2_CID_MPEG_AUDIO_EMPHASIS:      return "Audio Emphasis";
     816                 :          0 :         case V4L2_CID_MPEG_AUDIO_CRC:           return "Audio CRC";
     817                 :          0 :         case V4L2_CID_MPEG_AUDIO_MUTE:          return "Audio Mute";
     818                 :          0 :         case V4L2_CID_MPEG_AUDIO_AAC_BITRATE:   return "Audio AAC Bitrate";
     819                 :          0 :         case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:   return "Audio AC-3 Bitrate";
     820                 :          0 :         case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK:  return "Audio Playback";
     821                 :          0 :         case V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK: return "Audio Multilingual Playback";
     822                 :          0 :         case V4L2_CID_MPEG_VIDEO_ENCODING:      return "Video Encoding";
     823                 :          0 :         case V4L2_CID_MPEG_VIDEO_ASPECT:        return "Video Aspect";
     824                 :          0 :         case V4L2_CID_MPEG_VIDEO_B_FRAMES:      return "Video B Frames";
     825                 :          0 :         case V4L2_CID_MPEG_VIDEO_GOP_SIZE:      return "Video GOP Size";
     826                 :          0 :         case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:   return "Video GOP Closure";
     827                 :          0 :         case V4L2_CID_MPEG_VIDEO_PULLDOWN:      return "Video Pulldown";
     828                 :          3 :         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:  return "Video Bitrate Mode";
     829                 :          3 :         case V4L2_CID_MPEG_VIDEO_BITRATE:       return "Video Bitrate";
     830                 :          0 :         case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:  return "Video Peak Bitrate";
     831                 :          0 :         case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
     832                 :          0 :         case V4L2_CID_MPEG_VIDEO_MUTE:          return "Video Mute";
     833                 :          0 :         case V4L2_CID_MPEG_VIDEO_MUTE_YUV:      return "Video Mute YUV";
     834                 :          0 :         case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE:       return "Decoder Slice Interface";
     835                 :          0 :         case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:  return "MPEG4 Loop Filter Enable";
     836                 :          0 :         case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:       return "Number of Intra Refresh MBs";
     837                 :          0 :         case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:               return "Frame Level Rate Control Enable";
     838                 :          0 :         case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE:                  return "H264 MB Level Rate Control";
     839                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEADER_MODE:                   return "Sequence Header Mode";
     840                 :          0 :         case V4L2_CID_MPEG_VIDEO_MAX_REF_PIC:                   return "Max Number of Reference Pics";
     841                 :          0 :         case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP:               return "H263 I-Frame QP Value";
     842                 :          0 :         case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP:               return "H263 P-Frame QP Value";
     843                 :          0 :         case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP:               return "H263 B-Frame QP Value";
     844                 :          0 :         case V4L2_CID_MPEG_VIDEO_H263_MIN_QP:                   return "H263 Minimum QP Value";
     845                 :          0 :         case V4L2_CID_MPEG_VIDEO_H263_MAX_QP:                   return "H263 Maximum QP Value";
     846                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:               return "H264 I-Frame QP Value";
     847                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:               return "H264 P-Frame QP Value";
     848                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP:               return "H264 B-Frame QP Value";
     849                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:                   return "H264 Maximum QP Value";
     850                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:                   return "H264 Minimum QP Value";
     851                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM:            return "H264 8x8 Transform Enable";
     852                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE:                 return "H264 CPB Buffer Size";
     853                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:             return "H264 Entropy Mode";
     854                 :          3 :         case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:                 return "H264 I-Frame Period";
     855                 :          3 :         case V4L2_CID_MPEG_VIDEO_H264_LEVEL:                    return "H264 Level";
     856                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA:        return "H264 Loop Filter Alpha Offset";
     857                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA:         return "H264 Loop Filter Beta Offset";
     858                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:         return "H264 Loop Filter Mode";
     859                 :          3 :         case V4L2_CID_MPEG_VIDEO_H264_PROFILE:                  return "H264 Profile";
     860                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT:       return "Vertical Size of SAR";
     861                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH:        return "Horizontal Size of SAR";
     862                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE:           return "Aspect Ratio VUI Enable";
     863                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC:              return "VUI Aspect Ratio IDC";
     864                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_SEI_FRAME_PACKING:        return "H264 Enable Frame Packing SEI";
     865                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_SEI_FP_CURRENT_FRAME_0:   return "H264 Set Curr. Frame as Frame0";
     866                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE:  return "H264 FP Arrangement Type";
     867                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_FMO:                      return "H264 Flexible MB Ordering";
     868                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE:             return "H264 Map Type for FMO";
     869                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_FMO_SLICE_GROUP:          return "H264 FMO Number of Slice Groups";
     870                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_DIRECTION:     return "H264 FMO Direction of Change";
     871                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_RATE:          return "H264 FMO Size of 1st Slice Grp";
     872                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_FMO_RUN_LENGTH:           return "H264 FMO No. of Consecutive MBs";
     873                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_ASO:                      return "H264 Arbitrary Slice Ordering";
     874                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_ASO_SLICE_ORDER:          return "H264 ASO Slice Order";
     875                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING:      return "Enable H264 Hierarchical Coding";
     876                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE: return "H264 Hierarchical Coding Type";
     877                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER:return "H264 Number of HC Layers";
     878                 :            :         case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER_QP:
     879                 :          0 :                                                                 return "H264 Set QP Value for HC Layers";
     880                 :            :         case V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION:
     881                 :          0 :                                                                 return "H264 Constrained Intra Pred";
     882                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET:   return "H264 Chroma QP Index Offset";
     883                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QP:           return "H264 I-Frame Minimum QP Value";
     884                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QP:           return "H264 I-Frame Maximum QP Value";
     885                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QP:           return "H264 P-Frame Minimum QP Value";
     886                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QP:           return "H264 P-Frame Maximum QP Value";
     887                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_SPS:                      return "H264 Sequence Parameter Set";
     888                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_PPS:                      return "H264 Picture Parameter Set";
     889                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_SCALING_MATRIX:           return "H264 Scaling Matrix";
     890                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAMS:             return "H264 Slice Parameters";
     891                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS:            return "H264 Decode Parameters";
     892                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_DECODE_MODE:              return "H264 Decode Mode";
     893                 :          0 :         case V4L2_CID_MPEG_VIDEO_H264_START_CODE:               return "H264 Start Code";
     894                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL:                   return "MPEG2 Level";
     895                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE:                 return "MPEG2 Profile";
     896                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:              return "MPEG4 I-Frame QP Value";
     897                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:              return "MPEG4 P-Frame QP Value";
     898                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP:              return "MPEG4 B-Frame QP Value";
     899                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP:                  return "MPEG4 Minimum QP Value";
     900                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP:                  return "MPEG4 Maximum QP Value";
     901                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:                   return "MPEG4 Level";
     902                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:                 return "MPEG4 Profile";
     903                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL:                    return "Quarter Pixel Search Enable";
     904                 :          0 :         case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:         return "Maximum Bytes in a Slice";
     905                 :          0 :         case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:            return "Number of MBs in a Slice";
     906                 :          0 :         case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:              return "Slice Partitioning Method";
     907                 :          0 :         case V4L2_CID_MPEG_VIDEO_VBV_SIZE:                      return "VBV Buffer Size";
     908                 :          0 :         case V4L2_CID_MPEG_VIDEO_DEC_PTS:                       return "Video Decoder PTS";
     909                 :          0 :         case V4L2_CID_MPEG_VIDEO_DEC_FRAME:                     return "Video Decoder Frame Count";
     910                 :          0 :         case V4L2_CID_MPEG_VIDEO_VBV_DELAY:                     return "Initial Delay for VBV Control";
     911                 :          0 :         case V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE:             return "Horizontal MV Search Range";
     912                 :          0 :         case V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE:             return "Vertical MV Search Range";
     913                 :          3 :         case V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER:             return "Repeat Sequence Header";
     914                 :          3 :         case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME:               return "Force Key Frame";
     915                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS:            return "MPEG-2 Slice Parameters";
     916                 :          0 :         case V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION:            return "MPEG-2 Quantization Matrices";
     917                 :          0 :         case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS:                   return "FWHT Stateless Parameters";
     918                 :          0 :         case V4L2_CID_FWHT_I_FRAME_QP:                          return "FWHT I-Frame QP Value";
     919                 :          0 :         case V4L2_CID_FWHT_P_FRAME_QP:                          return "FWHT P-Frame QP Value";
     920                 :            : 
     921                 :            :         /* VPX controls */
     922                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS:            return "VPX Number of Partitions";
     923                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4:           return "VPX Intra Mode Decision Disable";
     924                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES:            return "VPX No. of Refs for P Frame";
     925                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL:              return "VPX Loop Filter Level Range";
     926                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS:          return "VPX Deblocking Effect Control";
     927                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD:   return "VPX Golden Frame Refresh Period";
     928                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL:          return "VPX Golden Frame Indicator";
     929                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_MIN_QP:                    return "VPX Minimum QP Value";
     930                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_MAX_QP:                    return "VPX Maximum QP Value";
     931                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP:                return "VPX I-Frame QP Value";
     932                 :          0 :         case V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP:                return "VPX P-Frame QP Value";
     933                 :          0 :         case V4L2_CID_MPEG_VIDEO_VP8_PROFILE:                   return "VP8 Profile";
     934                 :          0 :         case V4L2_CID_MPEG_VIDEO_VP9_PROFILE:                   return "VP9 Profile";
     935                 :          0 :         case V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER:              return "VP8 Frame Header";
     936                 :            : 
     937                 :            :         /* HEVC controls */
     938                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP:               return "HEVC I-Frame QP Value";
     939                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP:               return "HEVC P-Frame QP Value";
     940                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP:               return "HEVC B-Frame QP Value";
     941                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP:                   return "HEVC Minimum QP Value";
     942                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP:                   return "HEVC Maximum QP Value";
     943                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE:                  return "HEVC Profile";
     944                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL:                    return "HEVC Level";
     945                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_TIER:                     return "HEVC Tier";
     946                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_FRAME_RATE_RESOLUTION:    return "HEVC Frame Rate Resolution";
     947                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_MAX_PARTITION_DEPTH:      return "HEVC Maximum Coding Unit Depth";
     948                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE:             return "HEVC Refresh Type";
     949                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_CONST_INTRA_PRED:         return "HEVC Constant Intra Prediction";
     950                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_LOSSLESS_CU:              return "HEVC Lossless Encoding";
     951                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_WAVEFRONT:                return "HEVC Wavefront";
     952                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE:         return "HEVC Loop Filter";
     953                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_QP:                  return "HEVC QP Values";
     954                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE:         return "HEVC Hierarchical Coding Type";
     955                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER:        return "HEVC Hierarchical Coding Layer";
     956                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_QP:        return "HEVC Hierarchical Layer 0 QP";
     957                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_QP:        return "HEVC Hierarchical Layer 1 QP";
     958                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_QP:        return "HEVC Hierarchical Layer 2 QP";
     959                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_QP:        return "HEVC Hierarchical Layer 3 QP";
     960                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_QP:        return "HEVC Hierarchical Layer 4 QP";
     961                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_QP:        return "HEVC Hierarchical Layer 5 QP";
     962                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_QP:        return "HEVC Hierarchical Layer 6 QP";
     963                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR:        return "HEVC Hierarchical Lay 0 BitRate";
     964                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR:        return "HEVC Hierarchical Lay 1 BitRate";
     965                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR:        return "HEVC Hierarchical Lay 2 BitRate";
     966                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR:        return "HEVC Hierarchical Lay 3 BitRate";
     967                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR:        return "HEVC Hierarchical Lay 4 BitRate";
     968                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR:        return "HEVC Hierarchical Lay 5 BitRate";
     969                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR:        return "HEVC Hierarchical Lay 6 BitRate";
     970                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_GENERAL_PB:               return "HEVC General PB";
     971                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_TEMPORAL_ID:              return "HEVC Temporal ID";
     972                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_STRONG_SMOOTHING:         return "HEVC Strong Intra Smoothing";
     973                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_INTRA_PU_SPLIT:           return "HEVC Intra PU Split";
     974                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_TMV_PREDICTION:           return "HEVC TMV Prediction";
     975                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_MAX_NUM_MERGE_MV_MINUS1:  return "HEVC Max Num of Candidate MVs";
     976                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_WITHOUT_STARTCODE:        return "HEVC ENC Without Startcode";
     977                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_PERIOD:           return "HEVC Num of I-Frame b/w 2 IDR";
     978                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_LF_BETA_OFFSET_DIV2:      return "HEVC Loop Filter Beta Offset";
     979                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_LF_TC_OFFSET_DIV2:        return "HEVC Loop Filter TC Offset";
     980                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD:     return "HEVC Size of Length Field";
     981                 :          0 :         case V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES:        return "Reference Frames for a P-Frame";
     982                 :          0 :         case V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR:         return "Prepend SPS and PPS to IDR";
     983                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_SPS:                      return "HEVC Sequence Parameter Set";
     984                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_PPS:                      return "HEVC Picture Parameter Set";
     985                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS:             return "HEVC Slice Parameters";
     986                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_SCALING_MATRIX:           return "HEVC Scaling Matrix";
     987                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE:              return "HEVC Decode Mode";
     988                 :          0 :         case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE:               return "HEVC Start Code";
     989                 :            : 
     990                 :            :         /* CAMERA controls */
     991                 :            :         /* Keep the order of the 'case's the same as in v4l2-controls.h! */
     992                 :          0 :         case V4L2_CID_CAMERA_CLASS:             return "Camera Controls";
     993                 :          0 :         case V4L2_CID_EXPOSURE_AUTO:            return "Auto Exposure";
     994                 :          0 :         case V4L2_CID_EXPOSURE_ABSOLUTE:        return "Exposure Time, Absolute";
     995                 :          0 :         case V4L2_CID_EXPOSURE_AUTO_PRIORITY:   return "Exposure, Dynamic Framerate";
     996                 :          0 :         case V4L2_CID_PAN_RELATIVE:             return "Pan, Relative";
     997                 :          0 :         case V4L2_CID_TILT_RELATIVE:            return "Tilt, Relative";
     998                 :          0 :         case V4L2_CID_PAN_RESET:                return "Pan, Reset";
     999                 :          0 :         case V4L2_CID_TILT_RESET:               return "Tilt, Reset";
    1000                 :          0 :         case V4L2_CID_PAN_ABSOLUTE:             return "Pan, Absolute";
    1001                 :          0 :         case V4L2_CID_TILT_ABSOLUTE:            return "Tilt, Absolute";
    1002                 :          0 :         case V4L2_CID_FOCUS_ABSOLUTE:           return "Focus, Absolute";
    1003                 :          0 :         case V4L2_CID_FOCUS_RELATIVE:           return "Focus, Relative";
    1004                 :          0 :         case V4L2_CID_FOCUS_AUTO:               return "Focus, Automatic Continuous";
    1005                 :          0 :         case V4L2_CID_ZOOM_ABSOLUTE:            return "Zoom, Absolute";
    1006                 :          0 :         case V4L2_CID_ZOOM_RELATIVE:            return "Zoom, Relative";
    1007                 :          0 :         case V4L2_CID_ZOOM_CONTINUOUS:          return "Zoom, Continuous";
    1008                 :          0 :         case V4L2_CID_PRIVACY:                  return "Privacy";
    1009                 :          0 :         case V4L2_CID_IRIS_ABSOLUTE:            return "Iris, Absolute";
    1010                 :          0 :         case V4L2_CID_IRIS_RELATIVE:            return "Iris, Relative";
    1011                 :          0 :         case V4L2_CID_AUTO_EXPOSURE_BIAS:       return "Auto Exposure, Bias";
    1012                 :          0 :         case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE: return "White Balance, Auto & Preset";
    1013                 :          0 :         case V4L2_CID_WIDE_DYNAMIC_RANGE:       return "Wide Dynamic Range";
    1014                 :          0 :         case V4L2_CID_IMAGE_STABILIZATION:      return "Image Stabilization";
    1015                 :          0 :         case V4L2_CID_ISO_SENSITIVITY:          return "ISO Sensitivity";
    1016                 :          0 :         case V4L2_CID_ISO_SENSITIVITY_AUTO:     return "ISO Sensitivity, Auto";
    1017                 :          0 :         case V4L2_CID_EXPOSURE_METERING:        return "Exposure, Metering Mode";
    1018                 :          0 :         case V4L2_CID_SCENE_MODE:               return "Scene Mode";
    1019                 :          0 :         case V4L2_CID_3A_LOCK:                  return "3A Lock";
    1020                 :          0 :         case V4L2_CID_AUTO_FOCUS_START:         return "Auto Focus, Start";
    1021                 :          0 :         case V4L2_CID_AUTO_FOCUS_STOP:          return "Auto Focus, Stop";
    1022                 :          0 :         case V4L2_CID_AUTO_FOCUS_STATUS:        return "Auto Focus, Status";
    1023                 :          0 :         case V4L2_CID_AUTO_FOCUS_RANGE:         return "Auto Focus, Range";
    1024                 :          0 :         case V4L2_CID_PAN_SPEED:                return "Pan, Speed";
    1025                 :          0 :         case V4L2_CID_TILT_SPEED:               return "Tilt, Speed";
    1026                 :          0 :         case V4L2_CID_UNIT_CELL_SIZE:           return "Unit Cell Size";
    1027                 :          0 :         case V4L2_CID_CAMERA_ORIENTATION:       return "Camera Orientation";
    1028                 :          0 :         case V4L2_CID_CAMERA_SENSOR_ROTATION:   return "Camera Sensor Rotation";
    1029                 :            : 
    1030                 :            :         /* FM Radio Modulator controls */
    1031                 :            :         /* Keep the order of the 'case's the same as in v4l2-controls.h! */
    1032                 :          0 :         case V4L2_CID_FM_TX_CLASS:              return "FM Radio Modulator Controls";
    1033                 :          0 :         case V4L2_CID_RDS_TX_DEVIATION:         return "RDS Signal Deviation";
    1034                 :          0 :         case V4L2_CID_RDS_TX_PI:                return "RDS Program ID";
    1035                 :          0 :         case V4L2_CID_RDS_TX_PTY:               return "RDS Program Type";
    1036                 :          0 :         case V4L2_CID_RDS_TX_PS_NAME:           return "RDS PS Name";
    1037                 :          0 :         case V4L2_CID_RDS_TX_RADIO_TEXT:        return "RDS Radio Text";
    1038                 :          0 :         case V4L2_CID_RDS_TX_MONO_STEREO:       return "RDS Stereo";
    1039                 :          0 :         case V4L2_CID_RDS_TX_ARTIFICIAL_HEAD:   return "RDS Artificial Head";
    1040                 :          0 :         case V4L2_CID_RDS_TX_COMPRESSED:        return "RDS Compressed";
    1041                 :          0 :         case V4L2_CID_RDS_TX_DYNAMIC_PTY:       return "RDS Dynamic PTY";
    1042                 :          0 :         case V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT: return "RDS Traffic Announcement";
    1043                 :          0 :         case V4L2_CID_RDS_TX_TRAFFIC_PROGRAM:   return "RDS Traffic Program";
    1044                 :          0 :         case V4L2_CID_RDS_TX_MUSIC_SPEECH:      return "RDS Music";
    1045                 :          0 :         case V4L2_CID_RDS_TX_ALT_FREQS_ENABLE:  return "RDS Enable Alt Frequencies";
    1046                 :          0 :         case V4L2_CID_RDS_TX_ALT_FREQS:         return "RDS Alternate Frequencies";
    1047                 :          0 :         case V4L2_CID_AUDIO_LIMITER_ENABLED:    return "Audio Limiter Feature Enabled";
    1048                 :          0 :         case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: return "Audio Limiter Release Time";
    1049                 :          0 :         case V4L2_CID_AUDIO_LIMITER_DEVIATION:  return "Audio Limiter Deviation";
    1050                 :          0 :         case V4L2_CID_AUDIO_COMPRESSION_ENABLED: return "Audio Compression Enabled";
    1051                 :          0 :         case V4L2_CID_AUDIO_COMPRESSION_GAIN:   return "Audio Compression Gain";
    1052                 :          0 :         case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: return "Audio Compression Threshold";
    1053                 :          0 :         case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: return "Audio Compression Attack Time";
    1054                 :          0 :         case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: return "Audio Compression Release Time";
    1055                 :          0 :         case V4L2_CID_PILOT_TONE_ENABLED:       return "Pilot Tone Feature Enabled";
    1056                 :          0 :         case V4L2_CID_PILOT_TONE_DEVIATION:     return "Pilot Tone Deviation";
    1057                 :          0 :         case V4L2_CID_PILOT_TONE_FREQUENCY:     return "Pilot Tone Frequency";
    1058                 :          0 :         case V4L2_CID_TUNE_PREEMPHASIS:         return "Pre-Emphasis";
    1059                 :          0 :         case V4L2_CID_TUNE_POWER_LEVEL:         return "Tune Power Level";
    1060                 :          0 :         case V4L2_CID_TUNE_ANTENNA_CAPACITOR:   return "Tune Antenna Capacitor";
    1061                 :            : 
    1062                 :            :         /* Flash controls */
    1063                 :            :         /* Keep the order of the 'case's the same as in v4l2-controls.h! */
    1064                 :          0 :         case V4L2_CID_FLASH_CLASS:              return "Flash Controls";
    1065                 :          0 :         case V4L2_CID_FLASH_LED_MODE:           return "LED Mode";
    1066                 :          0 :         case V4L2_CID_FLASH_STROBE_SOURCE:      return "Strobe Source";
    1067                 :          0 :         case V4L2_CID_FLASH_STROBE:             return "Strobe";
    1068                 :          0 :         case V4L2_CID_FLASH_STROBE_STOP:        return "Stop Strobe";
    1069                 :          0 :         case V4L2_CID_FLASH_STROBE_STATUS:      return "Strobe Status";
    1070                 :          0 :         case V4L2_CID_FLASH_TIMEOUT:            return "Strobe Timeout";
    1071                 :          0 :         case V4L2_CID_FLASH_INTENSITY:          return "Intensity, Flash Mode";
    1072                 :          0 :         case V4L2_CID_FLASH_TORCH_INTENSITY:    return "Intensity, Torch Mode";
    1073                 :          0 :         case V4L2_CID_FLASH_INDICATOR_INTENSITY: return "Intensity, Indicator";
    1074                 :          0 :         case V4L2_CID_FLASH_FAULT:              return "Faults";
    1075                 :          0 :         case V4L2_CID_FLASH_CHARGE:             return "Charge";
    1076                 :          0 :         case V4L2_CID_FLASH_READY:              return "Ready to Strobe";
    1077                 :            : 
    1078                 :            :         /* JPEG encoder controls */
    1079                 :            :         /* Keep the order of the 'case's the same as in v4l2-controls.h! */
    1080                 :          0 :         case V4L2_CID_JPEG_CLASS:               return "JPEG Compression Controls";
    1081                 :          0 :         case V4L2_CID_JPEG_CHROMA_SUBSAMPLING:  return "Chroma Subsampling";
    1082                 :          0 :         case V4L2_CID_JPEG_RESTART_INTERVAL:    return "Restart Interval";
    1083                 :          0 :         case V4L2_CID_JPEG_COMPRESSION_QUALITY: return "Compression Quality";
    1084                 :          0 :         case V4L2_CID_JPEG_ACTIVE_MARKER:       return "Active Markers";
    1085                 :            : 
    1086                 :            :         /* Image source controls */
    1087                 :            :         /* Keep the order of the 'case's the same as in v4l2-controls.h! */
    1088                 :          0 :         case V4L2_CID_IMAGE_SOURCE_CLASS:       return "Image Source Controls";
    1089                 :          0 :         case V4L2_CID_VBLANK:                   return "Vertical Blanking";
    1090                 :          0 :         case V4L2_CID_HBLANK:                   return "Horizontal Blanking";
    1091                 :          0 :         case V4L2_CID_ANALOGUE_GAIN:            return "Analogue Gain";
    1092                 :          0 :         case V4L2_CID_TEST_PATTERN_RED:         return "Red Pixel Value";
    1093                 :          0 :         case V4L2_CID_TEST_PATTERN_GREENR:      return "Green (Red) Pixel Value";
    1094                 :          0 :         case V4L2_CID_TEST_PATTERN_BLUE:        return "Blue Pixel Value";
    1095                 :          0 :         case V4L2_CID_TEST_PATTERN_GREENB:      return "Green (Blue) Pixel Value";
    1096                 :            : 
    1097                 :            :         /* Image processing controls */
    1098                 :            :         /* Keep the order of the 'case's the same as in v4l2-controls.h! */
    1099                 :          3 :         case V4L2_CID_IMAGE_PROC_CLASS:         return "Image Processing Controls";
    1100                 :          0 :         case V4L2_CID_LINK_FREQ:                return "Link Frequency";
    1101                 :          0 :         case V4L2_CID_PIXEL_RATE:               return "Pixel Rate";
    1102                 :          0 :         case V4L2_CID_TEST_PATTERN:             return "Test Pattern";
    1103                 :          0 :         case V4L2_CID_DEINTERLACING_MODE:       return "Deinterlacing Mode";
    1104                 :          3 :         case V4L2_CID_DIGITAL_GAIN:             return "Digital Gain";
    1105                 :            : 
    1106                 :            :         /* DV controls */
    1107                 :            :         /* Keep the order of the 'case's the same as in v4l2-controls.h! */
    1108                 :          0 :         case V4L2_CID_DV_CLASS:                 return "Digital Video Controls";
    1109                 :          0 :         case V4L2_CID_DV_TX_HOTPLUG:            return "Hotplug Present";
    1110                 :          0 :         case V4L2_CID_DV_TX_RXSENSE:            return "RxSense Present";
    1111                 :          0 :         case V4L2_CID_DV_TX_EDID_PRESENT:       return "EDID Present";
    1112                 :          0 :         case V4L2_CID_DV_TX_MODE:               return "Transmit Mode";
    1113                 :          0 :         case V4L2_CID_DV_TX_RGB_RANGE:          return "Tx RGB Quantization Range";
    1114                 :          0 :         case V4L2_CID_DV_TX_IT_CONTENT_TYPE:    return "Tx IT Content Type";
    1115                 :          0 :         case V4L2_CID_DV_RX_POWER_PRESENT:      return "Power Present";
    1116                 :          0 :         case V4L2_CID_DV_RX_RGB_RANGE:          return "Rx RGB Quantization Range";
    1117                 :          0 :         case V4L2_CID_DV_RX_IT_CONTENT_TYPE:    return "Rx IT Content Type";
    1118                 :            : 
    1119                 :          0 :         case V4L2_CID_FM_RX_CLASS:              return "FM Radio Receiver Controls";
    1120                 :          0 :         case V4L2_CID_TUNE_DEEMPHASIS:          return "De-Emphasis";
    1121                 :          0 :         case V4L2_CID_RDS_RECEPTION:            return "RDS Reception";
    1122                 :          0 :         case V4L2_CID_RF_TUNER_CLASS:           return "RF Tuner Controls";
    1123                 :          0 :         case V4L2_CID_RF_TUNER_RF_GAIN:         return "RF Gain";
    1124                 :          0 :         case V4L2_CID_RF_TUNER_LNA_GAIN_AUTO:   return "LNA Gain, Auto";
    1125                 :          0 :         case V4L2_CID_RF_TUNER_LNA_GAIN:        return "LNA Gain";
    1126                 :          0 :         case V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO: return "Mixer Gain, Auto";
    1127                 :          0 :         case V4L2_CID_RF_TUNER_MIXER_GAIN:      return "Mixer Gain";
    1128                 :          0 :         case V4L2_CID_RF_TUNER_IF_GAIN_AUTO:    return "IF Gain, Auto";
    1129                 :          0 :         case V4L2_CID_RF_TUNER_IF_GAIN:         return "IF Gain";
    1130                 :          0 :         case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:  return "Bandwidth, Auto";
    1131                 :          0 :         case V4L2_CID_RF_TUNER_BANDWIDTH:       return "Bandwidth";
    1132                 :          0 :         case V4L2_CID_RF_TUNER_PLL_LOCK:        return "PLL Lock";
    1133                 :          0 :         case V4L2_CID_RDS_RX_PTY:               return "RDS Program Type";
    1134                 :          0 :         case V4L2_CID_RDS_RX_PS_NAME:           return "RDS PS Name";
    1135                 :          0 :         case V4L2_CID_RDS_RX_RADIO_TEXT:        return "RDS Radio Text";
    1136                 :          0 :         case V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT: return "RDS Traffic Announcement";
    1137                 :          0 :         case V4L2_CID_RDS_RX_TRAFFIC_PROGRAM:   return "RDS Traffic Program";
    1138                 :          0 :         case V4L2_CID_RDS_RX_MUSIC_SPEECH:      return "RDS Music";
    1139                 :            : 
    1140                 :            :         /* Detection controls */
    1141                 :            :         /* Keep the order of the 'case's the same as in v4l2-controls.h! */
    1142                 :          0 :         case V4L2_CID_DETECT_CLASS:             return "Detection Controls";
    1143                 :          0 :         case V4L2_CID_DETECT_MD_MODE:           return "Motion Detection Mode";
    1144                 :          0 :         case V4L2_CID_DETECT_MD_GLOBAL_THRESHOLD: return "MD Global Threshold";
    1145                 :          0 :         case V4L2_CID_DETECT_MD_THRESHOLD_GRID: return "MD Threshold Grid";
    1146                 :          0 :         case V4L2_CID_DETECT_MD_REGION_GRID:    return "MD Region Grid";
    1147                 :            :         default:
    1148                 :          0 :                 return NULL;
    1149                 :            :         }
    1150                 :            : }
    1151                 :            : EXPORT_SYMBOL(v4l2_ctrl_get_name);
    1152                 :            : 
    1153                 :          3 : void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
    1154                 :            :                     s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags)
    1155                 :            : {
    1156                 :          3 :         *name = v4l2_ctrl_get_name(id);
    1157                 :          3 :         *flags = 0;
    1158                 :            : 
    1159                 :          3 :         switch (id) {
    1160                 :            :         case V4L2_CID_AUDIO_MUTE:
    1161                 :            :         case V4L2_CID_AUDIO_LOUDNESS:
    1162                 :            :         case V4L2_CID_AUTO_WHITE_BALANCE:
    1163                 :            :         case V4L2_CID_AUTOGAIN:
    1164                 :            :         case V4L2_CID_HFLIP:
    1165                 :            :         case V4L2_CID_VFLIP:
    1166                 :            :         case V4L2_CID_HUE_AUTO:
    1167                 :            :         case V4L2_CID_CHROMA_AGC:
    1168                 :            :         case V4L2_CID_COLOR_KILLER:
    1169                 :            :         case V4L2_CID_AUTOBRIGHTNESS:
    1170                 :            :         case V4L2_CID_MPEG_AUDIO_MUTE:
    1171                 :            :         case V4L2_CID_MPEG_VIDEO_MUTE:
    1172                 :            :         case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
    1173                 :            :         case V4L2_CID_MPEG_VIDEO_PULLDOWN:
    1174                 :            :         case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
    1175                 :            :         case V4L2_CID_FOCUS_AUTO:
    1176                 :            :         case V4L2_CID_PRIVACY:
    1177                 :            :         case V4L2_CID_AUDIO_LIMITER_ENABLED:
    1178                 :            :         case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
    1179                 :            :         case V4L2_CID_PILOT_TONE_ENABLED:
    1180                 :            :         case V4L2_CID_ILLUMINATORS_1:
    1181                 :            :         case V4L2_CID_ILLUMINATORS_2:
    1182                 :            :         case V4L2_CID_FLASH_STROBE_STATUS:
    1183                 :            :         case V4L2_CID_FLASH_CHARGE:
    1184                 :            :         case V4L2_CID_FLASH_READY:
    1185                 :            :         case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:
    1186                 :            :         case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE:
    1187                 :            :         case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:
    1188                 :            :         case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE:
    1189                 :            :         case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM:
    1190                 :            :         case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE:
    1191                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL:
    1192                 :            :         case V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER:
    1193                 :            :         case V4L2_CID_WIDE_DYNAMIC_RANGE:
    1194                 :            :         case V4L2_CID_IMAGE_STABILIZATION:
    1195                 :            :         case V4L2_CID_RDS_RECEPTION:
    1196                 :            :         case V4L2_CID_RF_TUNER_LNA_GAIN_AUTO:
    1197                 :            :         case V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO:
    1198                 :            :         case V4L2_CID_RF_TUNER_IF_GAIN_AUTO:
    1199                 :            :         case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
    1200                 :            :         case V4L2_CID_RF_TUNER_PLL_LOCK:
    1201                 :            :         case V4L2_CID_RDS_TX_MONO_STEREO:
    1202                 :            :         case V4L2_CID_RDS_TX_ARTIFICIAL_HEAD:
    1203                 :            :         case V4L2_CID_RDS_TX_COMPRESSED:
    1204                 :            :         case V4L2_CID_RDS_TX_DYNAMIC_PTY:
    1205                 :            :         case V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT:
    1206                 :            :         case V4L2_CID_RDS_TX_TRAFFIC_PROGRAM:
    1207                 :            :         case V4L2_CID_RDS_TX_MUSIC_SPEECH:
    1208                 :            :         case V4L2_CID_RDS_TX_ALT_FREQS_ENABLE:
    1209                 :            :         case V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT:
    1210                 :            :         case V4L2_CID_RDS_RX_TRAFFIC_PROGRAM:
    1211                 :            :         case V4L2_CID_RDS_RX_MUSIC_SPEECH:
    1212                 :          3 :                 *type = V4L2_CTRL_TYPE_BOOLEAN;
    1213                 :          3 :                 *min = 0;
    1214                 :          3 :                 *max = *step = 1;
    1215                 :          3 :                 break;
    1216                 :            :         case V4L2_CID_ROTATE:
    1217                 :          0 :                 *type = V4L2_CTRL_TYPE_INTEGER;
    1218                 :          0 :                 *flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
    1219                 :          0 :                 break;
    1220                 :            :         case V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE:
    1221                 :            :         case V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE:
    1222                 :          0 :                 *type = V4L2_CTRL_TYPE_INTEGER;
    1223                 :          0 :                 break;
    1224                 :            :         case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME:
    1225                 :            :         case V4L2_CID_PAN_RESET:
    1226                 :            :         case V4L2_CID_TILT_RESET:
    1227                 :            :         case V4L2_CID_FLASH_STROBE:
    1228                 :            :         case V4L2_CID_FLASH_STROBE_STOP:
    1229                 :            :         case V4L2_CID_AUTO_FOCUS_START:
    1230                 :            :         case V4L2_CID_AUTO_FOCUS_STOP:
    1231                 :            :         case V4L2_CID_DO_WHITE_BALANCE:
    1232                 :          3 :                 *type = V4L2_CTRL_TYPE_BUTTON;
    1233                 :          3 :                 *flags |= V4L2_CTRL_FLAG_WRITE_ONLY |
    1234                 :            :                           V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
    1235                 :          3 :                 *min = *max = *step = *def = 0;
    1236                 :          3 :                 break;
    1237                 :            :         case V4L2_CID_POWER_LINE_FREQUENCY:
    1238                 :            :         case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
    1239                 :            :         case V4L2_CID_MPEG_AUDIO_ENCODING:
    1240                 :            :         case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
    1241                 :            :         case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
    1242                 :            :         case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
    1243                 :            :         case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
    1244                 :            :         case V4L2_CID_MPEG_AUDIO_MODE:
    1245                 :            :         case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
    1246                 :            :         case V4L2_CID_MPEG_AUDIO_EMPHASIS:
    1247                 :            :         case V4L2_CID_MPEG_AUDIO_CRC:
    1248                 :            :         case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK:
    1249                 :            :         case V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK:
    1250                 :            :         case V4L2_CID_MPEG_VIDEO_ENCODING:
    1251                 :            :         case V4L2_CID_MPEG_VIDEO_ASPECT:
    1252                 :            :         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
    1253                 :            :         case V4L2_CID_MPEG_STREAM_TYPE:
    1254                 :            :         case V4L2_CID_MPEG_STREAM_VBI_FMT:
    1255                 :            :         case V4L2_CID_EXPOSURE_AUTO:
    1256                 :            :         case V4L2_CID_AUTO_FOCUS_RANGE:
    1257                 :            :         case V4L2_CID_COLORFX:
    1258                 :            :         case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
    1259                 :            :         case V4L2_CID_TUNE_PREEMPHASIS:
    1260                 :            :         case V4L2_CID_FLASH_LED_MODE:
    1261                 :            :         case V4L2_CID_FLASH_STROBE_SOURCE:
    1262                 :            :         case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
    1263                 :            :         case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
    1264                 :            :         case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
    1265                 :            :         case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
    1266                 :            :         case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
    1267                 :            :         case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
    1268                 :            :         case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC:
    1269                 :            :         case V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE:
    1270                 :            :         case V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE:
    1271                 :            :         case V4L2_CID_MPEG_VIDEO_H264_DECODE_MODE:
    1272                 :            :         case V4L2_CID_MPEG_VIDEO_H264_START_CODE:
    1273                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL:
    1274                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE:
    1275                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
    1276                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
    1277                 :            :         case V4L2_CID_JPEG_CHROMA_SUBSAMPLING:
    1278                 :            :         case V4L2_CID_ISO_SENSITIVITY_AUTO:
    1279                 :            :         case V4L2_CID_EXPOSURE_METERING:
    1280                 :            :         case V4L2_CID_SCENE_MODE:
    1281                 :            :         case V4L2_CID_DV_TX_MODE:
    1282                 :            :         case V4L2_CID_DV_TX_RGB_RANGE:
    1283                 :            :         case V4L2_CID_DV_TX_IT_CONTENT_TYPE:
    1284                 :            :         case V4L2_CID_DV_RX_RGB_RANGE:
    1285                 :            :         case V4L2_CID_DV_RX_IT_CONTENT_TYPE:
    1286                 :            :         case V4L2_CID_TEST_PATTERN:
    1287                 :            :         case V4L2_CID_DEINTERLACING_MODE:
    1288                 :            :         case V4L2_CID_TUNE_DEEMPHASIS:
    1289                 :            :         case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL:
    1290                 :            :         case V4L2_CID_MPEG_VIDEO_VP8_PROFILE:
    1291                 :            :         case V4L2_CID_MPEG_VIDEO_VP9_PROFILE:
    1292                 :            :         case V4L2_CID_DETECT_MD_MODE:
    1293                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE:
    1294                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL:
    1295                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE:
    1296                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE:
    1297                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD:
    1298                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_TIER:
    1299                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE:
    1300                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE:
    1301                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE:
    1302                 :            :         case V4L2_CID_CAMERA_ORIENTATION:
    1303                 :          3 :                 *type = V4L2_CTRL_TYPE_MENU;
    1304                 :          3 :                 break;
    1305                 :            :         case V4L2_CID_LINK_FREQ:
    1306                 :          0 :                 *type = V4L2_CTRL_TYPE_INTEGER_MENU;
    1307                 :          0 :                 break;
    1308                 :            :         case V4L2_CID_RDS_TX_PS_NAME:
    1309                 :            :         case V4L2_CID_RDS_TX_RADIO_TEXT:
    1310                 :            :         case V4L2_CID_RDS_RX_PS_NAME:
    1311                 :            :         case V4L2_CID_RDS_RX_RADIO_TEXT:
    1312                 :          0 :                 *type = V4L2_CTRL_TYPE_STRING;
    1313                 :          0 :                 break;
    1314                 :            :         case V4L2_CID_ISO_SENSITIVITY:
    1315                 :            :         case V4L2_CID_AUTO_EXPOSURE_BIAS:
    1316                 :            :         case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS:
    1317                 :            :         case V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES:
    1318                 :          0 :                 *type = V4L2_CTRL_TYPE_INTEGER_MENU;
    1319                 :          0 :                 break;
    1320                 :            :         case V4L2_CID_USER_CLASS:
    1321                 :            :         case V4L2_CID_CAMERA_CLASS:
    1322                 :            :         case V4L2_CID_MPEG_CLASS:
    1323                 :            :         case V4L2_CID_FM_TX_CLASS:
    1324                 :            :         case V4L2_CID_FLASH_CLASS:
    1325                 :            :         case V4L2_CID_JPEG_CLASS:
    1326                 :            :         case V4L2_CID_IMAGE_SOURCE_CLASS:
    1327                 :            :         case V4L2_CID_IMAGE_PROC_CLASS:
    1328                 :            :         case V4L2_CID_DV_CLASS:
    1329                 :            :         case V4L2_CID_FM_RX_CLASS:
    1330                 :            :         case V4L2_CID_RF_TUNER_CLASS:
    1331                 :            :         case V4L2_CID_DETECT_CLASS:
    1332                 :          3 :                 *type = V4L2_CTRL_TYPE_CTRL_CLASS;
    1333                 :            :                 /* You can neither read not write these */
    1334                 :          3 :                 *flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
    1335                 :          3 :                 *min = *max = *step = *def = 0;
    1336                 :          3 :                 break;
    1337                 :            :         case V4L2_CID_BG_COLOR:
    1338                 :          0 :                 *type = V4L2_CTRL_TYPE_INTEGER;
    1339                 :          0 :                 *step = 1;
    1340                 :          0 :                 *min = 0;
    1341                 :            :                 /* Max is calculated as RGB888 that is 2^24 */
    1342                 :          0 :                 *max = 0xFFFFFF;
    1343                 :          0 :                 break;
    1344                 :            :         case V4L2_CID_FLASH_FAULT:
    1345                 :            :         case V4L2_CID_JPEG_ACTIVE_MARKER:
    1346                 :            :         case V4L2_CID_3A_LOCK:
    1347                 :            :         case V4L2_CID_AUTO_FOCUS_STATUS:
    1348                 :            :         case V4L2_CID_DV_TX_HOTPLUG:
    1349                 :            :         case V4L2_CID_DV_TX_RXSENSE:
    1350                 :            :         case V4L2_CID_DV_TX_EDID_PRESENT:
    1351                 :            :         case V4L2_CID_DV_RX_POWER_PRESENT:
    1352                 :          0 :                 *type = V4L2_CTRL_TYPE_BITMASK;
    1353                 :          0 :                 break;
    1354                 :            :         case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
    1355                 :            :         case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
    1356                 :          3 :                 *type = V4L2_CTRL_TYPE_INTEGER;
    1357                 :          3 :                 *flags |= V4L2_CTRL_FLAG_READ_ONLY;
    1358                 :          3 :                 break;
    1359                 :            :         case V4L2_CID_MPEG_VIDEO_DEC_PTS:
    1360                 :          0 :                 *type = V4L2_CTRL_TYPE_INTEGER64;
    1361                 :          0 :                 *flags |= V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY;
    1362                 :          0 :                 *min = *def = 0;
    1363                 :          0 :                 *max = 0x1ffffffffLL;
    1364                 :          0 :                 *step = 1;
    1365                 :          0 :                 break;
    1366                 :            :         case V4L2_CID_MPEG_VIDEO_DEC_FRAME:
    1367                 :          0 :                 *type = V4L2_CTRL_TYPE_INTEGER64;
    1368                 :          0 :                 *flags |= V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY;
    1369                 :          0 :                 *min = *def = 0;
    1370                 :          0 :                 *max = 0x7fffffffffffffffLL;
    1371                 :          0 :                 *step = 1;
    1372                 :          0 :                 break;
    1373                 :            :         case V4L2_CID_PIXEL_RATE:
    1374                 :          0 :                 *type = V4L2_CTRL_TYPE_INTEGER64;
    1375                 :          0 :                 *flags |= V4L2_CTRL_FLAG_READ_ONLY;
    1376                 :          0 :                 break;
    1377                 :            :         case V4L2_CID_DETECT_MD_REGION_GRID:
    1378                 :          0 :                 *type = V4L2_CTRL_TYPE_U8;
    1379                 :          0 :                 break;
    1380                 :            :         case V4L2_CID_DETECT_MD_THRESHOLD_GRID:
    1381                 :          0 :                 *type = V4L2_CTRL_TYPE_U16;
    1382                 :          0 :                 break;
    1383                 :            :         case V4L2_CID_RDS_TX_ALT_FREQS:
    1384                 :          0 :                 *type = V4L2_CTRL_TYPE_U32;
    1385                 :          0 :                 break;
    1386                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS:
    1387                 :          0 :                 *type = V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS;
    1388                 :          0 :                 break;
    1389                 :            :         case V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION:
    1390                 :          0 :                 *type = V4L2_CTRL_TYPE_MPEG2_QUANTIZATION;
    1391                 :          0 :                 break;
    1392                 :            :         case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS:
    1393                 :          0 :                 *type = V4L2_CTRL_TYPE_FWHT_PARAMS;
    1394                 :          0 :                 break;
    1395                 :            :         case V4L2_CID_MPEG_VIDEO_H264_SPS:
    1396                 :          0 :                 *type = V4L2_CTRL_TYPE_H264_SPS;
    1397                 :          0 :                 break;
    1398                 :            :         case V4L2_CID_MPEG_VIDEO_H264_PPS:
    1399                 :          0 :                 *type = V4L2_CTRL_TYPE_H264_PPS;
    1400                 :          0 :                 break;
    1401                 :            :         case V4L2_CID_MPEG_VIDEO_H264_SCALING_MATRIX:
    1402                 :          0 :                 *type = V4L2_CTRL_TYPE_H264_SCALING_MATRIX;
    1403                 :          0 :                 break;
    1404                 :            :         case V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAMS:
    1405                 :          0 :                 *type = V4L2_CTRL_TYPE_H264_SLICE_PARAMS;
    1406                 :          0 :                 break;
    1407                 :            :         case V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS:
    1408                 :          0 :                 *type = V4L2_CTRL_TYPE_H264_DECODE_PARAMS;
    1409                 :          0 :                 break;
    1410                 :            :         case V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER:
    1411                 :          0 :                 *type = V4L2_CTRL_TYPE_VP8_FRAME_HEADER;
    1412                 :          0 :                 break;
    1413                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_SPS:
    1414                 :          0 :                 *type = V4L2_CTRL_TYPE_HEVC_SPS;
    1415                 :          0 :                 break;
    1416                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_PPS:
    1417                 :          0 :                 *type = V4L2_CTRL_TYPE_HEVC_PPS;
    1418                 :          0 :                 break;
    1419                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS:
    1420                 :          0 :                 *type = V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS;
    1421                 :          0 :                 break;
    1422                 :            :         case V4L2_CID_MPEG_VIDEO_HEVC_SCALING_MATRIX:
    1423                 :          0 :                 *type = V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX;
    1424                 :          0 :                 break;
    1425                 :            :         case V4L2_CID_UNIT_CELL_SIZE:
    1426                 :          0 :                 *type = V4L2_CTRL_TYPE_AREA;
    1427                 :          0 :                 *flags |= V4L2_CTRL_FLAG_READ_ONLY;
    1428                 :          0 :                 break;
    1429                 :            :         default:
    1430                 :          3 :                 *type = V4L2_CTRL_TYPE_INTEGER;
    1431                 :          3 :                 break;
    1432                 :            :         }
    1433                 :          3 :         switch (id) {
    1434                 :            :         case V4L2_CID_MPEG_AUDIO_ENCODING:
    1435                 :            :         case V4L2_CID_MPEG_AUDIO_MODE:
    1436                 :            :         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
    1437                 :            :         case V4L2_CID_MPEG_VIDEO_B_FRAMES:
    1438                 :            :         case V4L2_CID_MPEG_STREAM_TYPE:
    1439                 :          3 :                 *flags |= V4L2_CTRL_FLAG_UPDATE;
    1440                 :          3 :                 break;
    1441                 :            :         case V4L2_CID_AUDIO_VOLUME:
    1442                 :            :         case V4L2_CID_AUDIO_BALANCE:
    1443                 :            :         case V4L2_CID_AUDIO_BASS:
    1444                 :            :         case V4L2_CID_AUDIO_TREBLE:
    1445                 :            :         case V4L2_CID_BRIGHTNESS:
    1446                 :            :         case V4L2_CID_CONTRAST:
    1447                 :            :         case V4L2_CID_SATURATION:
    1448                 :            :         case V4L2_CID_HUE:
    1449                 :            :         case V4L2_CID_RED_BALANCE:
    1450                 :            :         case V4L2_CID_BLUE_BALANCE:
    1451                 :            :         case V4L2_CID_GAMMA:
    1452                 :            :         case V4L2_CID_SHARPNESS:
    1453                 :            :         case V4L2_CID_CHROMA_GAIN:
    1454                 :            :         case V4L2_CID_RDS_TX_DEVIATION:
    1455                 :            :         case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
    1456                 :            :         case V4L2_CID_AUDIO_LIMITER_DEVIATION:
    1457                 :            :         case V4L2_CID_AUDIO_COMPRESSION_GAIN:
    1458                 :            :         case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
    1459                 :            :         case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
    1460                 :            :         case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
    1461                 :            :         case V4L2_CID_PILOT_TONE_DEVIATION:
    1462                 :            :         case V4L2_CID_PILOT_TONE_FREQUENCY:
    1463                 :            :         case V4L2_CID_TUNE_POWER_LEVEL:
    1464                 :            :         case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
    1465                 :            :         case V4L2_CID_RF_TUNER_RF_GAIN:
    1466                 :            :         case V4L2_CID_RF_TUNER_LNA_GAIN:
    1467                 :            :         case V4L2_CID_RF_TUNER_MIXER_GAIN:
    1468                 :            :         case V4L2_CID_RF_TUNER_IF_GAIN:
    1469                 :            :         case V4L2_CID_RF_TUNER_BANDWIDTH:
    1470                 :            :         case V4L2_CID_DETECT_MD_GLOBAL_THRESHOLD:
    1471                 :          3 :                 *flags |= V4L2_CTRL_FLAG_SLIDER;
    1472                 :          3 :                 break;
    1473                 :            :         case V4L2_CID_PAN_RELATIVE:
    1474                 :            :         case V4L2_CID_TILT_RELATIVE:
    1475                 :            :         case V4L2_CID_FOCUS_RELATIVE:
    1476                 :            :         case V4L2_CID_IRIS_RELATIVE:
    1477                 :            :         case V4L2_CID_ZOOM_RELATIVE:
    1478                 :          0 :                 *flags |= V4L2_CTRL_FLAG_WRITE_ONLY |
    1479                 :            :                           V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
    1480                 :          0 :                 break;
    1481                 :            :         case V4L2_CID_FLASH_STROBE_STATUS:
    1482                 :            :         case V4L2_CID_AUTO_FOCUS_STATUS:
    1483                 :            :         case V4L2_CID_FLASH_READY:
    1484                 :            :         case V4L2_CID_DV_TX_HOTPLUG:
    1485                 :            :         case V4L2_CID_DV_TX_RXSENSE:
    1486                 :            :         case V4L2_CID_DV_TX_EDID_PRESENT:
    1487                 :            :         case V4L2_CID_DV_RX_POWER_PRESENT:
    1488                 :            :         case V4L2_CID_DV_RX_IT_CONTENT_TYPE:
    1489                 :            :         case V4L2_CID_RDS_RX_PTY:
    1490                 :            :         case V4L2_CID_RDS_RX_PS_NAME:
    1491                 :            :         case V4L2_CID_RDS_RX_RADIO_TEXT:
    1492                 :            :         case V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT:
    1493                 :            :         case V4L2_CID_RDS_RX_TRAFFIC_PROGRAM:
    1494                 :            :         case V4L2_CID_RDS_RX_MUSIC_SPEECH:
    1495                 :            :         case V4L2_CID_CAMERA_ORIENTATION:
    1496                 :            :         case V4L2_CID_CAMERA_SENSOR_ROTATION:
    1497                 :          0 :                 *flags |= V4L2_CTRL_FLAG_READ_ONLY;
    1498                 :          0 :                 break;
    1499                 :            :         case V4L2_CID_RF_TUNER_PLL_LOCK:
    1500                 :          0 :                 *flags |= V4L2_CTRL_FLAG_VOLATILE;
    1501                 :          0 :                 break;
    1502                 :            :         }
    1503                 :          3 : }
    1504                 :            : EXPORT_SYMBOL(v4l2_ctrl_fill);
    1505                 :            : 
    1506                 :            : static u32 user_flags(const struct v4l2_ctrl *ctrl)
    1507                 :            : {
    1508                 :          0 :         u32 flags = ctrl->flags;
    1509                 :            : 
    1510                 :          0 :         if (ctrl->is_ptr)
    1511                 :          0 :                 flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD;
    1512                 :            : 
    1513                 :            :         return flags;
    1514                 :            : }
    1515                 :            : 
    1516                 :          0 : static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl, u32 changes)
    1517                 :            : {
    1518                 :          0 :         memset(ev, 0, sizeof(*ev));
    1519                 :          0 :         ev->type = V4L2_EVENT_CTRL;
    1520                 :          0 :         ev->id = ctrl->id;
    1521                 :          0 :         ev->u.ctrl.changes = changes;
    1522                 :          0 :         ev->u.ctrl.type = ctrl->type;
    1523                 :          0 :         ev->u.ctrl.flags = user_flags(ctrl);
    1524                 :          0 :         if (ctrl->is_ptr)
    1525                 :          0 :                 ev->u.ctrl.value64 = 0;
    1526                 :            :         else
    1527                 :          0 :                 ev->u.ctrl.value64 = *ctrl->p_cur.p_s64;
    1528                 :          0 :         ev->u.ctrl.minimum = ctrl->minimum;
    1529                 :          0 :         ev->u.ctrl.maximum = ctrl->maximum;
    1530                 :          0 :         if (ctrl->type == V4L2_CTRL_TYPE_MENU
    1531                 :          0 :             || ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU)
    1532                 :          0 :                 ev->u.ctrl.step = 1;
    1533                 :            :         else
    1534                 :          0 :                 ev->u.ctrl.step = ctrl->step;
    1535                 :          0 :         ev->u.ctrl.default_value = ctrl->default_value;
    1536                 :          0 : }
    1537                 :            : 
    1538                 :          0 : static void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes)
    1539                 :            : {
    1540                 :            :         struct v4l2_event ev;
    1541                 :            :         struct v4l2_subscribed_event *sev;
    1542                 :            : 
    1543                 :          0 :         if (list_empty(&ctrl->ev_subs))
    1544                 :          0 :                 return;
    1545                 :          0 :         fill_event(&ev, ctrl, changes);
    1546                 :            : 
    1547                 :          0 :         list_for_each_entry(sev, &ctrl->ev_subs, node)
    1548                 :          0 :                 if (sev->fh != fh ||
    1549                 :          0 :                     (sev->flags & V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK))
    1550                 :          0 :                         v4l2_event_queue_fh(sev->fh, &ev);
    1551                 :            : }
    1552                 :            : 
    1553                 :          0 : static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
    1554                 :            :                       union v4l2_ctrl_ptr ptr1,
    1555                 :            :                       union v4l2_ctrl_ptr ptr2)
    1556                 :            : {
    1557                 :          0 :         switch (ctrl->type) {
    1558                 :            :         case V4L2_CTRL_TYPE_BUTTON:
    1559                 :            :                 return false;
    1560                 :            :         case V4L2_CTRL_TYPE_STRING:
    1561                 :          0 :                 idx *= ctrl->elem_size;
    1562                 :            :                 /* strings are always 0-terminated */
    1563                 :          0 :                 return !strcmp(ptr1.p_char + idx, ptr2.p_char + idx);
    1564                 :            :         case V4L2_CTRL_TYPE_INTEGER64:
    1565                 :          0 :                 return ptr1.p_s64[idx] == ptr2.p_s64[idx];
    1566                 :            :         case V4L2_CTRL_TYPE_U8:
    1567                 :          0 :                 return ptr1.p_u8[idx] == ptr2.p_u8[idx];
    1568                 :            :         case V4L2_CTRL_TYPE_U16:
    1569                 :          0 :                 return ptr1.p_u16[idx] == ptr2.p_u16[idx];
    1570                 :            :         case V4L2_CTRL_TYPE_U32:
    1571                 :          0 :                 return ptr1.p_u32[idx] == ptr2.p_u32[idx];
    1572                 :            :         default:
    1573                 :          0 :                 if (ctrl->is_int)
    1574                 :          0 :                         return ptr1.p_s32[idx] == ptr2.p_s32[idx];
    1575                 :          0 :                 idx *= ctrl->elem_size;
    1576                 :          0 :                 return !memcmp(ptr1.p + idx, ptr2.p + idx, ctrl->elem_size);
    1577                 :            :         }
    1578                 :            : }
    1579                 :            : 
    1580                 :          0 : static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx,
    1581                 :            :                               union v4l2_ctrl_ptr ptr)
    1582                 :            : {
    1583                 :            :         struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
    1584                 :          0 :         void *p = ptr.p + idx * ctrl->elem_size;
    1585                 :            : 
    1586                 :          0 :         memset(p, 0, ctrl->elem_size);
    1587                 :            : 
    1588                 :            :         /*
    1589                 :            :          * The cast is needed to get rid of a gcc warning complaining that
    1590                 :            :          * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the
    1591                 :            :          * v4l2_ctrl_type enum.
    1592                 :            :          */
    1593                 :          0 :         switch ((u32)ctrl->type) {
    1594                 :            :         case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
    1595                 :            :                 p_mpeg2_slice_params = p;
    1596                 :            :                 /* 4:2:0 */
    1597                 :          0 :                 p_mpeg2_slice_params->sequence.chroma_format = 1;
    1598                 :            :                 /* interlaced top field */
    1599                 :          0 :                 p_mpeg2_slice_params->picture.picture_structure = 1;
    1600                 :          0 :                 p_mpeg2_slice_params->picture.picture_coding_type =
    1601                 :            :                                         V4L2_MPEG2_PICTURE_CODING_TYPE_I;
    1602                 :          0 :                 break;
    1603                 :            :         }
    1604                 :          0 : }
    1605                 :            : 
    1606                 :          3 : static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
    1607                 :            :                      union v4l2_ctrl_ptr ptr)
    1608                 :            : {
    1609                 :          3 :         switch (ctrl->type) {
    1610                 :            :         case V4L2_CTRL_TYPE_STRING:
    1611                 :          0 :                 idx *= ctrl->elem_size;
    1612                 :          0 :                 memset(ptr.p_char + idx, ' ', ctrl->minimum);
    1613                 :          0 :                 ptr.p_char[idx + ctrl->minimum] = '\0';
    1614                 :          0 :                 break;
    1615                 :            :         case V4L2_CTRL_TYPE_INTEGER64:
    1616                 :          0 :                 ptr.p_s64[idx] = ctrl->default_value;
    1617                 :          0 :                 break;
    1618                 :            :         case V4L2_CTRL_TYPE_INTEGER:
    1619                 :            :         case V4L2_CTRL_TYPE_INTEGER_MENU:
    1620                 :            :         case V4L2_CTRL_TYPE_MENU:
    1621                 :            :         case V4L2_CTRL_TYPE_BITMASK:
    1622                 :            :         case V4L2_CTRL_TYPE_BOOLEAN:
    1623                 :          3 :                 ptr.p_s32[idx] = ctrl->default_value;
    1624                 :          3 :                 break;
    1625                 :            :         case V4L2_CTRL_TYPE_BUTTON:
    1626                 :            :         case V4L2_CTRL_TYPE_CTRL_CLASS:
    1627                 :          3 :                 ptr.p_s32[idx] = 0;
    1628                 :          3 :                 break;
    1629                 :            :         case V4L2_CTRL_TYPE_U8:
    1630                 :          3 :                 ptr.p_u8[idx] = ctrl->default_value;
    1631                 :          3 :                 break;
    1632                 :            :         case V4L2_CTRL_TYPE_U16:
    1633                 :          0 :                 ptr.p_u16[idx] = ctrl->default_value;
    1634                 :          0 :                 break;
    1635                 :            :         case V4L2_CTRL_TYPE_U32:
    1636                 :          0 :                 ptr.p_u32[idx] = ctrl->default_value;
    1637                 :          0 :                 break;
    1638                 :            :         default:
    1639                 :          0 :                 std_init_compound(ctrl, idx, ptr);
    1640                 :          0 :                 break;
    1641                 :            :         }
    1642                 :          3 : }
    1643                 :            : 
    1644                 :          0 : static void std_log(const struct v4l2_ctrl *ctrl)
    1645                 :            : {
    1646                 :          0 :         union v4l2_ctrl_ptr ptr = ctrl->p_cur;
    1647                 :            : 
    1648                 :          0 :         if (ctrl->is_array) {
    1649                 :            :                 unsigned i;
    1650                 :            : 
    1651                 :          0 :                 for (i = 0; i < ctrl->nr_of_dims; i++)
    1652                 :          0 :                         pr_cont("[%u]", ctrl->dims[i]);
    1653                 :          0 :                 pr_cont(" ");
    1654                 :            :         }
    1655                 :            : 
    1656                 :          0 :         switch (ctrl->type) {
    1657                 :            :         case V4L2_CTRL_TYPE_INTEGER:
    1658                 :          0 :                 pr_cont("%d", *ptr.p_s32);
    1659                 :          0 :                 break;
    1660                 :            :         case V4L2_CTRL_TYPE_BOOLEAN:
    1661                 :          0 :                 pr_cont("%s", *ptr.p_s32 ? "true" : "false");
    1662                 :          0 :                 break;
    1663                 :            :         case V4L2_CTRL_TYPE_MENU:
    1664                 :          0 :                 pr_cont("%s", ctrl->qmenu[*ptr.p_s32]);
    1665                 :          0 :                 break;
    1666                 :            :         case V4L2_CTRL_TYPE_INTEGER_MENU:
    1667                 :          0 :                 pr_cont("%lld", ctrl->qmenu_int[*ptr.p_s32]);
    1668                 :          0 :                 break;
    1669                 :            :         case V4L2_CTRL_TYPE_BITMASK:
    1670                 :          0 :                 pr_cont("0x%08x", *ptr.p_s32);
    1671                 :          0 :                 break;
    1672                 :            :         case V4L2_CTRL_TYPE_INTEGER64:
    1673                 :          0 :                 pr_cont("%lld", *ptr.p_s64);
    1674                 :          0 :                 break;
    1675                 :            :         case V4L2_CTRL_TYPE_STRING:
    1676                 :          0 :                 pr_cont("%s", ptr.p_char);
    1677                 :          0 :                 break;
    1678                 :            :         case V4L2_CTRL_TYPE_U8:
    1679                 :          0 :                 pr_cont("%u", (unsigned)*ptr.p_u8);
    1680                 :          0 :                 break;
    1681                 :            :         case V4L2_CTRL_TYPE_U16:
    1682                 :          0 :                 pr_cont("%u", (unsigned)*ptr.p_u16);
    1683                 :          0 :                 break;
    1684                 :            :         case V4L2_CTRL_TYPE_U32:
    1685                 :          0 :                 pr_cont("%u", (unsigned)*ptr.p_u32);
    1686                 :          0 :                 break;
    1687                 :            :         default:
    1688                 :          0 :                 pr_cont("unknown type %d", ctrl->type);
    1689                 :          0 :                 break;
    1690                 :            :         }
    1691                 :          0 : }
    1692                 :            : 
    1693                 :            : /*
    1694                 :            :  * Round towards the closest legal value. Be careful when we are
    1695                 :            :  * close to the maximum range of the control type to prevent
    1696                 :            :  * wrap-arounds.
    1697                 :            :  */
    1698                 :            : #define ROUND_TO_RANGE(val, offset_type, ctrl)                  \
    1699                 :            : ({                                                              \
    1700                 :            :         offset_type offset;                                     \
    1701                 :            :         if ((ctrl)->maximum >= 0 &&                               \
    1702                 :            :             val >= (ctrl)->maximum - (s32)((ctrl)->step / 2))  \
    1703                 :            :                 val = (ctrl)->maximum;                               \
    1704                 :            :         else                                                    \
    1705                 :            :                 val += (s32)((ctrl)->step / 2);                      \
    1706                 :            :         val = clamp_t(typeof(val), val,                         \
    1707                 :            :                       (ctrl)->minimum, (ctrl)->maximum);  \
    1708                 :            :         offset = (val) - (ctrl)->minimum;                    \
    1709                 :            :         offset = (ctrl)->step * (offset / (u32)(ctrl)->step);     \
    1710                 :            :         val = (ctrl)->minimum + offset;                              \
    1711                 :            :         0;                                                      \
    1712                 :            : })
    1713                 :            : 
    1714                 :            : /* Validate a new control */
    1715                 :            : 
    1716                 :            : #define zero_padding(s) \
    1717                 :            :         memset(&(s).padding, 0, sizeof((s).padding))
    1718                 :            : 
    1719                 :            : /*
    1720                 :            :  * Compound controls validation requires setting unused fields/flags to zero
    1721                 :            :  * in order to properly detect unchanged controls with std_equal's memcmp.
    1722                 :            :  */
    1723                 :          0 : static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
    1724                 :            :                                  union v4l2_ctrl_ptr ptr)
    1725                 :            : {
    1726                 :            :         struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
    1727                 :            :         struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
    1728                 :            :         struct v4l2_ctrl_hevc_sps *p_hevc_sps;
    1729                 :            :         struct v4l2_ctrl_hevc_pps *p_hevc_pps;
    1730                 :            :         struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
    1731                 :            :         struct v4l2_area *area;
    1732                 :          0 :         void *p = ptr.p + idx * ctrl->elem_size;
    1733                 :            :         unsigned int i;
    1734                 :            : 
    1735                 :          0 :         switch ((u32)ctrl->type) {
    1736                 :            :         case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
    1737                 :            :                 p_mpeg2_slice_params = p;
    1738                 :            : 
    1739                 :          0 :                 switch (p_mpeg2_slice_params->sequence.chroma_format) {
    1740                 :            :                 case 1: /* 4:2:0 */
    1741                 :            :                 case 2: /* 4:2:2 */
    1742                 :            :                 case 3: /* 4:4:4 */
    1743                 :            :                         break;
    1744                 :            :                 default:
    1745                 :            :                         return -EINVAL;
    1746                 :            :                 }
    1747                 :            : 
    1748                 :          0 :                 switch (p_mpeg2_slice_params->picture.intra_dc_precision) {
    1749                 :            :                 case 0: /* 8 bits */
    1750                 :            :                 case 1: /* 9 bits */
    1751                 :            :                 case 2: /* 10 bits */
    1752                 :            :                 case 3: /* 11 bits */
    1753                 :            :                         break;
    1754                 :            :                 default:
    1755                 :            :                         return -EINVAL;
    1756                 :            :                 }
    1757                 :            : 
    1758                 :          0 :                 switch (p_mpeg2_slice_params->picture.picture_structure) {
    1759                 :            :                 case 1: /* interlaced top field */
    1760                 :            :                 case 2: /* interlaced bottom field */
    1761                 :            :                 case 3: /* progressive */
    1762                 :            :                         break;
    1763                 :            :                 default:
    1764                 :            :                         return -EINVAL;
    1765                 :            :                 }
    1766                 :            : 
    1767                 :          0 :                 switch (p_mpeg2_slice_params->picture.picture_coding_type) {
    1768                 :            :                 case V4L2_MPEG2_PICTURE_CODING_TYPE_I:
    1769                 :            :                 case V4L2_MPEG2_PICTURE_CODING_TYPE_P:
    1770                 :            :                 case V4L2_MPEG2_PICTURE_CODING_TYPE_B:
    1771                 :            :                         break;
    1772                 :            :                 default:
    1773                 :            :                         return -EINVAL;
    1774                 :            :                 }
    1775                 :            : 
    1776                 :            :                 break;
    1777                 :            : 
    1778                 :            :         case V4L2_CTRL_TYPE_MPEG2_QUANTIZATION:
    1779                 :            :                 break;
    1780                 :            : 
    1781                 :            :         case V4L2_CTRL_TYPE_FWHT_PARAMS:
    1782                 :            :                 break;
    1783                 :            : 
    1784                 :            :         case V4L2_CTRL_TYPE_H264_SPS:
    1785                 :            :         case V4L2_CTRL_TYPE_H264_PPS:
    1786                 :            :         case V4L2_CTRL_TYPE_H264_SCALING_MATRIX:
    1787                 :            :         case V4L2_CTRL_TYPE_H264_SLICE_PARAMS:
    1788                 :            :         case V4L2_CTRL_TYPE_H264_DECODE_PARAMS:
    1789                 :            :                 break;
    1790                 :            : 
    1791                 :            :         case V4L2_CTRL_TYPE_VP8_FRAME_HEADER:
    1792                 :            :                 p_vp8_frame_header = p;
    1793                 :            : 
    1794                 :          0 :                 switch (p_vp8_frame_header->num_dct_parts) {
    1795                 :            :                 case 1:
    1796                 :            :                 case 2:
    1797                 :            :                 case 4:
    1798                 :            :                 case 8:
    1799                 :            :                         break;
    1800                 :            :                 default:
    1801                 :            :                         return -EINVAL;
    1802                 :            :                 }
    1803                 :          0 :                 zero_padding(p_vp8_frame_header->segment_header);
    1804                 :          0 :                 zero_padding(p_vp8_frame_header->lf_header);
    1805                 :          0 :                 zero_padding(p_vp8_frame_header->quant_header);
    1806                 :          0 :                 zero_padding(p_vp8_frame_header->entropy_header);
    1807                 :          0 :                 zero_padding(p_vp8_frame_header->coder_state);
    1808                 :          0 :                 break;
    1809                 :            : 
    1810                 :            :         case V4L2_CTRL_TYPE_HEVC_SPS:
    1811                 :            :                 p_hevc_sps = p;
    1812                 :            : 
    1813                 :          0 :                 if (!(p_hevc_sps->flags & V4L2_HEVC_SPS_FLAG_PCM_ENABLED)) {
    1814                 :          0 :                         p_hevc_sps->pcm_sample_bit_depth_luma_minus1 = 0;
    1815                 :          0 :                         p_hevc_sps->pcm_sample_bit_depth_chroma_minus1 = 0;
    1816                 :          0 :                         p_hevc_sps->log2_min_pcm_luma_coding_block_size_minus3 = 0;
    1817                 :          0 :                         p_hevc_sps->log2_diff_max_min_pcm_luma_coding_block_size = 0;
    1818                 :            :                 }
    1819                 :            : 
    1820                 :          0 :                 if (!(p_hevc_sps->flags &
    1821                 :            :                       V4L2_HEVC_SPS_FLAG_LONG_TERM_REF_PICS_PRESENT))
    1822                 :          0 :                         p_hevc_sps->num_long_term_ref_pics_sps = 0;
    1823                 :            :                 break;
    1824                 :            : 
    1825                 :            :         case V4L2_CTRL_TYPE_HEVC_PPS:
    1826                 :            :                 p_hevc_pps = p;
    1827                 :            : 
    1828                 :          0 :                 if (!(p_hevc_pps->flags &
    1829                 :            :                       V4L2_HEVC_PPS_FLAG_CU_QP_DELTA_ENABLED))
    1830                 :          0 :                         p_hevc_pps->diff_cu_qp_delta_depth = 0;
    1831                 :            : 
    1832                 :          0 :                 if (!(p_hevc_pps->flags & V4L2_HEVC_PPS_FLAG_TILES_ENABLED)) {
    1833                 :          0 :                         p_hevc_pps->num_tile_columns_minus1 = 0;
    1834                 :          0 :                         p_hevc_pps->num_tile_rows_minus1 = 0;
    1835                 :          0 :                         memset(&p_hevc_pps->column_width_minus1, 0,
    1836                 :            :                                sizeof(p_hevc_pps->column_width_minus1));
    1837                 :          0 :                         memset(&p_hevc_pps->row_height_minus1, 0,
    1838                 :            :                                sizeof(p_hevc_pps->row_height_minus1));
    1839                 :            : 
    1840                 :          0 :                         p_hevc_pps->flags &=
    1841                 :            :                                 ~V4L2_HEVC_PPS_FLAG_PPS_LOOP_FILTER_ACROSS_SLICES_ENABLED;
    1842                 :            :                 }
    1843                 :            : 
    1844                 :          0 :                 if (p_hevc_pps->flags &
    1845                 :            :                     V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER) {
    1846                 :          0 :                         p_hevc_pps->pps_beta_offset_div2 = 0;
    1847                 :          0 :                         p_hevc_pps->pps_tc_offset_div2 = 0;
    1848                 :            :                 }
    1849                 :            : 
    1850                 :          0 :                 zero_padding(*p_hevc_pps);
    1851                 :          0 :                 break;
    1852                 :            : 
    1853                 :            :         case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
    1854                 :            :                 p_hevc_slice_params = p;
    1855                 :            : 
    1856                 :          0 :                 if (p_hevc_slice_params->num_active_dpb_entries >
    1857                 :            :                     V4L2_HEVC_DPB_ENTRIES_NUM_MAX)
    1858                 :            :                         return -EINVAL;
    1859                 :            : 
    1860                 :          0 :                 zero_padding(p_hevc_slice_params->pred_weight_table);
    1861                 :            : 
    1862                 :          0 :                 for (i = 0; i < p_hevc_slice_params->num_active_dpb_entries;
    1863                 :          0 :                      i++) {
    1864                 :            :                         struct v4l2_hevc_dpb_entry *dpb_entry =
    1865                 :            :                                 &p_hevc_slice_params->dpb[i];
    1866                 :            : 
    1867                 :          0 :                         zero_padding(*dpb_entry);
    1868                 :            :                 }
    1869                 :            : 
    1870                 :          0 :                 zero_padding(*p_hevc_slice_params);
    1871                 :          0 :                 break;
    1872                 :            : 
    1873                 :            :         case V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX:
    1874                 :            :                 break;
    1875                 :            : 
    1876                 :            :         case V4L2_CTRL_TYPE_AREA:
    1877                 :            :                 area = p;
    1878                 :          0 :                 if (!area->width || !area->height)
    1879                 :            :                         return -EINVAL;
    1880                 :            :                 break;
    1881                 :            : 
    1882                 :            :         default:
    1883                 :            :                 return -EINVAL;
    1884                 :            :         }
    1885                 :            : 
    1886                 :            :         return 0;
    1887                 :            : }
    1888                 :            : 
    1889                 :          0 : static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
    1890                 :            :                         union v4l2_ctrl_ptr ptr)
    1891                 :            : {
    1892                 :            :         size_t len;
    1893                 :            :         u64 offset;
    1894                 :            :         s64 val;
    1895                 :            : 
    1896                 :          0 :         switch ((u32)ctrl->type) {
    1897                 :            :         case V4L2_CTRL_TYPE_INTEGER:
    1898                 :          0 :                 return ROUND_TO_RANGE(ptr.p_s32[idx], u32, ctrl);
    1899                 :            :         case V4L2_CTRL_TYPE_INTEGER64:
    1900                 :            :                 /*
    1901                 :            :                  * We can't use the ROUND_TO_RANGE define here due to
    1902                 :            :                  * the u64 divide that needs special care.
    1903                 :            :                  */
    1904                 :          0 :                 val = ptr.p_s64[idx];
    1905                 :          0 :                 if (ctrl->maximum >= 0 && val >= ctrl->maximum - (s64)(ctrl->step / 2))
    1906                 :            :                         val = ctrl->maximum;
    1907                 :            :                 else
    1908                 :          0 :                         val += (s64)(ctrl->step / 2);
    1909                 :          0 :                 val = clamp_t(s64, val, ctrl->minimum, ctrl->maximum);
    1910                 :          0 :                 offset = val - ctrl->minimum;
    1911                 :          0 :                 do_div(offset, ctrl->step);
    1912                 :          0 :                 ptr.p_s64[idx] = ctrl->minimum + offset * ctrl->step;
    1913                 :          0 :                 return 0;
    1914                 :            :         case V4L2_CTRL_TYPE_U8:
    1915                 :          0 :                 return ROUND_TO_RANGE(ptr.p_u8[idx], u8, ctrl);
    1916                 :            :         case V4L2_CTRL_TYPE_U16:
    1917                 :          0 :                 return ROUND_TO_RANGE(ptr.p_u16[idx], u16, ctrl);
    1918                 :            :         case V4L2_CTRL_TYPE_U32:
    1919                 :          0 :                 return ROUND_TO_RANGE(ptr.p_u32[idx], u32, ctrl);
    1920                 :            : 
    1921                 :            :         case V4L2_CTRL_TYPE_BOOLEAN:
    1922                 :          0 :                 ptr.p_s32[idx] = !!ptr.p_s32[idx];
    1923                 :          0 :                 return 0;
    1924                 :            : 
    1925                 :            :         case V4L2_CTRL_TYPE_MENU:
    1926                 :            :         case V4L2_CTRL_TYPE_INTEGER_MENU:
    1927                 :          0 :                 if (ptr.p_s32[idx] < ctrl->minimum || ptr.p_s32[idx] > ctrl->maximum)
    1928                 :            :                         return -ERANGE;
    1929                 :          0 :                 if (ctrl->menu_skip_mask & (1ULL << ptr.p_s32[idx]))
    1930                 :            :                         return -EINVAL;
    1931                 :          0 :                 if (ctrl->type == V4L2_CTRL_TYPE_MENU &&
    1932                 :          0 :                     ctrl->qmenu[ptr.p_s32[idx]][0] == '\0')
    1933                 :            :                         return -EINVAL;
    1934                 :          0 :                 return 0;
    1935                 :            : 
    1936                 :            :         case V4L2_CTRL_TYPE_BITMASK:
    1937                 :          0 :                 ptr.p_s32[idx] &= ctrl->maximum;
    1938                 :          0 :                 return 0;
    1939                 :            : 
    1940                 :            :         case V4L2_CTRL_TYPE_BUTTON:
    1941                 :            :         case V4L2_CTRL_TYPE_CTRL_CLASS:
    1942                 :          0 :                 ptr.p_s32[idx] = 0;
    1943                 :          0 :                 return 0;
    1944                 :            : 
    1945                 :            :         case V4L2_CTRL_TYPE_STRING:
    1946                 :          0 :                 idx *= ctrl->elem_size;
    1947                 :          0 :                 len = strlen(ptr.p_char + idx);
    1948                 :          0 :                 if (len < ctrl->minimum)
    1949                 :            :                         return -ERANGE;
    1950                 :          0 :                 if ((len - (u32)ctrl->minimum) % (u32)ctrl->step)
    1951                 :            :                         return -ERANGE;
    1952                 :          0 :                 return 0;
    1953                 :            : 
    1954                 :            :         default:
    1955                 :          0 :                 return std_validate_compound(ctrl, idx, ptr);
    1956                 :            :         }
    1957                 :            : }
    1958                 :            : 
    1959                 :            : static const struct v4l2_ctrl_type_ops std_type_ops = {
    1960                 :            :         .equal = std_equal,
    1961                 :            :         .init = std_init,
    1962                 :            :         .log = std_log,
    1963                 :            :         .validate = std_validate,
    1964                 :            : };
    1965                 :            : 
    1966                 :            : /* Helper function: copy the given control value back to the caller */
    1967                 :          0 : static int ptr_to_user(struct v4l2_ext_control *c,
    1968                 :            :                        struct v4l2_ctrl *ctrl,
    1969                 :            :                        union v4l2_ctrl_ptr ptr)
    1970                 :            : {
    1971                 :            :         u32 len;
    1972                 :            : 
    1973                 :          0 :         if (ctrl->is_ptr && !ctrl->is_string)
    1974                 :          0 :                 return copy_to_user(c->ptr, ptr.p, c->size) ?
    1975                 :          0 :                        -EFAULT : 0;
    1976                 :            : 
    1977                 :          0 :         switch (ctrl->type) {
    1978                 :            :         case V4L2_CTRL_TYPE_STRING:
    1979                 :          0 :                 len = strlen(ptr.p_char);
    1980                 :          0 :                 if (c->size < len + 1) {
    1981                 :          0 :                         c->size = ctrl->elem_size;
    1982                 :          0 :                         return -ENOSPC;
    1983                 :            :                 }
    1984                 :          0 :                 return copy_to_user(c->string, ptr.p_char, len + 1) ?
    1985                 :          0 :                        -EFAULT : 0;
    1986                 :            :         case V4L2_CTRL_TYPE_INTEGER64:
    1987                 :          0 :                 c->value64 = *ptr.p_s64;
    1988                 :          0 :                 break;
    1989                 :            :         default:
    1990                 :          0 :                 c->value = *ptr.p_s32;
    1991                 :          0 :                 break;
    1992                 :            :         }
    1993                 :            :         return 0;
    1994                 :            : }
    1995                 :            : 
    1996                 :            : /* Helper function: copy the current control value back to the caller */
    1997                 :          0 : static int cur_to_user(struct v4l2_ext_control *c,
    1998                 :            :                        struct v4l2_ctrl *ctrl)
    1999                 :            : {
    2000                 :          0 :         return ptr_to_user(c, ctrl, ctrl->p_cur);
    2001                 :            : }
    2002                 :            : 
    2003                 :            : /* Helper function: copy the new control value back to the caller */
    2004                 :          0 : static int new_to_user(struct v4l2_ext_control *c,
    2005                 :            :                        struct v4l2_ctrl *ctrl)
    2006                 :            : {
    2007                 :          0 :         return ptr_to_user(c, ctrl, ctrl->p_new);
    2008                 :            : }
    2009                 :            : 
    2010                 :            : /* Helper function: copy the request value back to the caller */
    2011                 :            : static int req_to_user(struct v4l2_ext_control *c,
    2012                 :            :                        struct v4l2_ctrl_ref *ref)
    2013                 :            : {
    2014                 :          0 :         return ptr_to_user(c, ref->ctrl, ref->p_req);
    2015                 :            : }
    2016                 :            : 
    2017                 :            : /* Helper function: copy the initial control value back to the caller */
    2018                 :          0 : static int def_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl)
    2019                 :            : {
    2020                 :            :         int idx;
    2021                 :            : 
    2022                 :          0 :         for (idx = 0; idx < ctrl->elems; idx++)
    2023                 :          0 :                 ctrl->type_ops->init(ctrl, idx, ctrl->p_new);
    2024                 :            : 
    2025                 :          0 :         return ptr_to_user(c, ctrl, ctrl->p_new);
    2026                 :            : }
    2027                 :            : 
    2028                 :            : /* Helper function: copy the caller-provider value to the given control value */
    2029                 :          0 : static int user_to_ptr(struct v4l2_ext_control *c,
    2030                 :            :                        struct v4l2_ctrl *ctrl,
    2031                 :            :                        union v4l2_ctrl_ptr ptr)
    2032                 :            : {
    2033                 :            :         int ret;
    2034                 :            :         u32 size;
    2035                 :            : 
    2036                 :          0 :         ctrl->is_new = 1;
    2037                 :          0 :         if (ctrl->is_ptr && !ctrl->is_string) {
    2038                 :            :                 unsigned idx;
    2039                 :            : 
    2040                 :          0 :                 ret = copy_from_user(ptr.p, c->ptr, c->size) ? -EFAULT : 0;
    2041                 :          0 :                 if (ret || !ctrl->is_array)
    2042                 :            :                         return ret;
    2043                 :          0 :                 for (idx = c->size / ctrl->elem_size; idx < ctrl->elems; idx++)
    2044                 :          0 :                         ctrl->type_ops->init(ctrl, idx, ptr);
    2045                 :            :                 return 0;
    2046                 :            :         }
    2047                 :            : 
    2048                 :          0 :         switch (ctrl->type) {
    2049                 :            :         case V4L2_CTRL_TYPE_INTEGER64:
    2050                 :          0 :                 *ptr.p_s64 = c->value64;
    2051                 :          0 :                 break;
    2052                 :            :         case V4L2_CTRL_TYPE_STRING:
    2053                 :          0 :                 size = c->size;
    2054                 :          0 :                 if (size == 0)
    2055                 :            :                         return -ERANGE;
    2056                 :          0 :                 if (size > ctrl->maximum + 1)
    2057                 :          0 :                         size = ctrl->maximum + 1;
    2058                 :          0 :                 ret = copy_from_user(ptr.p_char, c->string, size) ? -EFAULT : 0;
    2059                 :          0 :                 if (!ret) {
    2060                 :          0 :                         char last = ptr.p_char[size - 1];
    2061                 :            : 
    2062                 :          0 :                         ptr.p_char[size - 1] = 0;
    2063                 :            :                         /* If the string was longer than ctrl->maximum,
    2064                 :            :                            then return an error. */
    2065                 :          0 :                         if (strlen(ptr.p_char) == ctrl->maximum && last)
    2066                 :            :                                 return -ERANGE;
    2067                 :            :                 }
    2068                 :          0 :                 return ret;
    2069                 :            :         default:
    2070                 :          0 :                 *ptr.p_s32 = c->value;
    2071                 :          0 :                 break;
    2072                 :            :         }
    2073                 :            :         return 0;
    2074                 :            : }
    2075                 :            : 
    2076                 :            : /* Helper function: copy the caller-provider value as the new control value */
    2077                 :            : static int user_to_new(struct v4l2_ext_control *c,
    2078                 :            :                        struct v4l2_ctrl *ctrl)
    2079                 :            : {
    2080                 :          0 :         return user_to_ptr(c, ctrl, ctrl->p_new);
    2081                 :            : }
    2082                 :            : 
    2083                 :            : /* Copy the one value to another. */
    2084                 :            : static void ptr_to_ptr(struct v4l2_ctrl *ctrl,
    2085                 :            :                        union v4l2_ctrl_ptr from, union v4l2_ctrl_ptr to)
    2086                 :            : {
    2087                 :          3 :         if (ctrl == NULL)
    2088                 :            :                 return;
    2089                 :          3 :         memcpy(to.p, from.p, ctrl->elems * ctrl->elem_size);
    2090                 :            : }
    2091                 :            : 
    2092                 :            : /* Copy the new value to the current value. */
    2093                 :          0 : static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags)
    2094                 :            : {
    2095                 :            :         bool changed;
    2096                 :            : 
    2097                 :          0 :         if (ctrl == NULL)
    2098                 :          0 :                 return;
    2099                 :            : 
    2100                 :            :         /* has_changed is set by cluster_changed */
    2101                 :          0 :         changed = ctrl->has_changed;
    2102                 :          0 :         if (changed)
    2103                 :            :                 ptr_to_ptr(ctrl, ctrl->p_new, ctrl->p_cur);
    2104                 :            : 
    2105                 :          0 :         if (ch_flags & V4L2_EVENT_CTRL_CH_FLAGS) {
    2106                 :            :                 /* Note: CH_FLAGS is only set for auto clusters. */
    2107                 :          0 :                 ctrl->flags &=
    2108                 :            :                         ~(V4L2_CTRL_FLAG_INACTIVE | V4L2_CTRL_FLAG_VOLATILE);
    2109                 :          0 :                 if (!is_cur_manual(ctrl->cluster[0])) {
    2110                 :          0 :                         ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
    2111                 :          0 :                         if (ctrl->cluster[0]->has_volatiles)
    2112                 :          0 :                                 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
    2113                 :            :                 }
    2114                 :            :                 fh = NULL;
    2115                 :            :         }
    2116                 :          0 :         if (changed || ch_flags) {
    2117                 :            :                 /* If a control was changed that was not one of the controls
    2118                 :            :                    modified by the application, then send the event to all. */
    2119                 :          0 :                 if (!ctrl->is_new)
    2120                 :            :                         fh = NULL;
    2121                 :          0 :                 send_event(fh, ctrl,
    2122                 :            :                         (changed ? V4L2_EVENT_CTRL_CH_VALUE : 0) | ch_flags);
    2123                 :          0 :                 if (ctrl->call_notify && changed && ctrl->handler->notify)
    2124                 :          0 :                         ctrl->handler->notify(ctrl, ctrl->handler->notify_priv);
    2125                 :            :         }
    2126                 :            : }
    2127                 :            : 
    2128                 :            : /* Copy the current value to the new value */
    2129                 :          3 : static void cur_to_new(struct v4l2_ctrl *ctrl)
    2130                 :            : {
    2131                 :          3 :         if (ctrl == NULL)
    2132                 :          3 :                 return;
    2133                 :            :         ptr_to_ptr(ctrl, ctrl->p_cur, ctrl->p_new);
    2134                 :            : }
    2135                 :            : 
    2136                 :            : /* Copy the new value to the request value */
    2137                 :          0 : static void new_to_req(struct v4l2_ctrl_ref *ref)
    2138                 :            : {
    2139                 :          0 :         if (!ref)
    2140                 :          0 :                 return;
    2141                 :          0 :         ptr_to_ptr(ref->ctrl, ref->ctrl->p_new, ref->p_req);
    2142                 :          0 :         ref->req = ref;
    2143                 :            : }
    2144                 :            : 
    2145                 :            : /* Copy the request value to the new value */
    2146                 :          0 : static void req_to_new(struct v4l2_ctrl_ref *ref)
    2147                 :            : {
    2148                 :          0 :         if (!ref)
    2149                 :          0 :                 return;
    2150                 :          0 :         if (ref->req)
    2151                 :          0 :                 ptr_to_ptr(ref->ctrl, ref->req->p_req, ref->ctrl->p_new);
    2152                 :            :         else
    2153                 :          0 :                 ptr_to_ptr(ref->ctrl, ref->ctrl->p_cur, ref->ctrl->p_new);
    2154                 :            : }
    2155                 :            : 
    2156                 :            : /* Return non-zero if one or more of the controls in the cluster has a new
    2157                 :            :    value that differs from the current value. */
    2158                 :          0 : static int cluster_changed(struct v4l2_ctrl *master)
    2159                 :            : {
    2160                 :            :         bool changed = false;
    2161                 :            :         unsigned idx;
    2162                 :            :         int i;
    2163                 :            : 
    2164                 :          0 :         for (i = 0; i < master->ncontrols; i++) {
    2165                 :          0 :                 struct v4l2_ctrl *ctrl = master->cluster[i];
    2166                 :            :                 bool ctrl_changed = false;
    2167                 :            : 
    2168                 :          0 :                 if (ctrl == NULL)
    2169                 :          0 :                         continue;
    2170                 :            : 
    2171                 :          0 :                 if (ctrl->flags & V4L2_CTRL_FLAG_EXECUTE_ON_WRITE)
    2172                 :            :                         changed = ctrl_changed = true;
    2173                 :            : 
    2174                 :            :                 /*
    2175                 :            :                  * Set has_changed to false to avoid generating
    2176                 :            :                  * the event V4L2_EVENT_CTRL_CH_VALUE
    2177                 :            :                  */
    2178                 :          0 :                 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) {
    2179                 :          0 :                         ctrl->has_changed = false;
    2180                 :          0 :                         continue;
    2181                 :            :                 }
    2182                 :            : 
    2183                 :          0 :                 for (idx = 0; !ctrl_changed && idx < ctrl->elems; idx++)
    2184                 :          0 :                         ctrl_changed = !ctrl->type_ops->equal(ctrl, idx,
    2185                 :          0 :                                 ctrl->p_cur, ctrl->p_new);
    2186                 :          0 :                 ctrl->has_changed = ctrl_changed;
    2187                 :          0 :                 changed |= ctrl->has_changed;
    2188                 :            :         }
    2189                 :          0 :         return changed;
    2190                 :            : }
    2191                 :            : 
    2192                 :            : /* Control range checking */
    2193                 :          3 : static int check_range(enum v4l2_ctrl_type type,
    2194                 :            :                 s64 min, s64 max, u64 step, s64 def)
    2195                 :            : {
    2196                 :          3 :         switch (type) {
    2197                 :            :         case V4L2_CTRL_TYPE_BOOLEAN:
    2198                 :          3 :                 if (step != 1 || max > 1 || min < 0)
    2199                 :            :                         return -ERANGE;
    2200                 :            :                 /* fall through */
    2201                 :            :         case V4L2_CTRL_TYPE_U8:
    2202                 :            :         case V4L2_CTRL_TYPE_U16:
    2203                 :            :         case V4L2_CTRL_TYPE_U32:
    2204                 :            :         case V4L2_CTRL_TYPE_INTEGER:
    2205                 :            :         case V4L2_CTRL_TYPE_INTEGER64:
    2206                 :          3 :                 if (step == 0 || min > max || def < min || def > max)
    2207                 :            :                         return -ERANGE;
    2208                 :          3 :                 return 0;
    2209                 :            :         case V4L2_CTRL_TYPE_BITMASK:
    2210                 :          0 :                 if (step || min || !max || (def & ~max))
    2211                 :            :                         return -ERANGE;
    2212                 :          0 :                 return 0;
    2213                 :            :         case V4L2_CTRL_TYPE_MENU:
    2214                 :            :         case V4L2_CTRL_TYPE_INTEGER_MENU:
    2215                 :          3 :                 if (min > max || def < min || def > max)
    2216                 :            :                         return -ERANGE;
    2217                 :            :                 /* Note: step == menu_skip_mask for menu controls.
    2218                 :            :                    So here we check if the default value is masked out. */
    2219                 :          3 :                 if (step && ((1 << def) & step))
    2220                 :            :                         return -EINVAL;
    2221                 :          3 :                 return 0;
    2222                 :            :         case V4L2_CTRL_TYPE_STRING:
    2223                 :          0 :                 if (min > max || min < 0 || step < 1 || def)
    2224                 :            :                         return -ERANGE;
    2225                 :          0 :                 return 0;
    2226                 :            :         default:
    2227                 :            :                 return 0;
    2228                 :            :         }
    2229                 :            : }
    2230                 :            : 
    2231                 :            : /* Validate a new control */
    2232                 :            : static int validate_new(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr p_new)
    2233                 :            : {
    2234                 :            :         unsigned idx;
    2235                 :            :         int err = 0;
    2236                 :            : 
    2237                 :          0 :         for (idx = 0; !err && idx < ctrl->elems; idx++)
    2238                 :          0 :                 err = ctrl->type_ops->validate(ctrl, idx, p_new);
    2239                 :          0 :         return err;
    2240                 :            : }
    2241                 :            : 
    2242                 :            : static inline u32 node2id(struct list_head *node)
    2243                 :            : {
    2244                 :          3 :         return list_entry(node, struct v4l2_ctrl_ref, node)->ctrl->id;
    2245                 :            : }
    2246                 :            : 
    2247                 :            : /* Set the handler's error code if it wasn't set earlier already */
    2248                 :            : static inline int handler_set_err(struct v4l2_ctrl_handler *hdl, int err)
    2249                 :            : {
    2250                 :          0 :         if (hdl->error == 0)
    2251                 :          0 :                 hdl->error = err;
    2252                 :            :         return err;
    2253                 :            : }
    2254                 :            : 
    2255                 :            : /* Initialize the handler */
    2256                 :          3 : int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
    2257                 :            :                                  unsigned nr_of_controls_hint,
    2258                 :            :                                  struct lock_class_key *key, const char *name)
    2259                 :            : {
    2260                 :          3 :         mutex_init(&hdl->_lock);
    2261                 :          3 :         hdl->lock = &hdl->_lock;
    2262                 :            :         lockdep_set_class_and_name(hdl->lock, key, name);
    2263                 :          3 :         INIT_LIST_HEAD(&hdl->ctrls);
    2264                 :          3 :         INIT_LIST_HEAD(&hdl->ctrl_refs);
    2265                 :          3 :         INIT_LIST_HEAD(&hdl->requests);
    2266                 :          3 :         INIT_LIST_HEAD(&hdl->requests_queued);
    2267                 :          3 :         hdl->request_is_queued = false;
    2268                 :          3 :         hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8;
    2269                 :          3 :         hdl->buckets = kvmalloc_array(hdl->nr_of_buckets,
    2270                 :            :                                       sizeof(hdl->buckets[0]),
    2271                 :            :                                       GFP_KERNEL | __GFP_ZERO);
    2272                 :          3 :         hdl->error = hdl->buckets ? 0 : -ENOMEM;
    2273                 :          3 :         media_request_object_init(&hdl->req_obj);
    2274                 :          3 :         return hdl->error;
    2275                 :            : }
    2276                 :            : EXPORT_SYMBOL(v4l2_ctrl_handler_init_class);
    2277                 :            : 
    2278                 :            : /* Free all controls and control refs */
    2279                 :          3 : void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
    2280                 :            : {
    2281                 :            :         struct v4l2_ctrl_ref *ref, *next_ref;
    2282                 :            :         struct v4l2_ctrl *ctrl, *next_ctrl;
    2283                 :            :         struct v4l2_subscribed_event *sev, *next_sev;
    2284                 :            : 
    2285                 :          3 :         if (hdl == NULL || hdl->buckets == NULL)
    2286                 :          3 :                 return;
    2287                 :            : 
    2288                 :          3 :         if (!hdl->req_obj.req && !list_empty(&hdl->requests)) {
    2289                 :            :                 struct v4l2_ctrl_handler *req, *next_req;
    2290                 :            : 
    2291                 :          0 :                 list_for_each_entry_safe(req, next_req, &hdl->requests, requests) {
    2292                 :          0 :                         media_request_object_unbind(&req->req_obj);
    2293                 :          0 :                         media_request_object_put(&req->req_obj);
    2294                 :            :                 }
    2295                 :            :         }
    2296                 :          3 :         mutex_lock(hdl->lock);
    2297                 :            :         /* Free all nodes */
    2298                 :          3 :         list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) {
    2299                 :            :                 list_del(&ref->node);
    2300                 :          3 :                 kfree(ref);
    2301                 :            :         }
    2302                 :            :         /* Free all controls owned by the handler */
    2303                 :          3 :         list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) {
    2304                 :            :                 list_del(&ctrl->node);
    2305                 :          3 :                 list_for_each_entry_safe(sev, next_sev, &ctrl->ev_subs, node)
    2306                 :            :                         list_del(&sev->node);
    2307                 :          3 :                 kvfree(ctrl);
    2308                 :            :         }
    2309                 :          3 :         kvfree(hdl->buckets);
    2310                 :          3 :         hdl->buckets = NULL;
    2311                 :          3 :         hdl->cached = NULL;
    2312                 :          3 :         hdl->error = 0;
    2313                 :          3 :         mutex_unlock(hdl->lock);
    2314                 :            :         mutex_destroy(&hdl->_lock);
    2315                 :            : }
    2316                 :            : EXPORT_SYMBOL(v4l2_ctrl_handler_free);
    2317                 :            : 
    2318                 :            : /* For backwards compatibility: V4L2_CID_PRIVATE_BASE should no longer
    2319                 :            :    be used except in G_CTRL, S_CTRL, QUERYCTRL and QUERYMENU when dealing
    2320                 :            :    with applications that do not use the NEXT_CTRL flag.
    2321                 :            : 
    2322                 :            :    We just find the n-th private user control. It's O(N), but that should not
    2323                 :            :    be an issue in this particular case. */
    2324                 :          0 : static struct v4l2_ctrl_ref *find_private_ref(
    2325                 :            :                 struct v4l2_ctrl_handler *hdl, u32 id)
    2326                 :            : {
    2327                 :            :         struct v4l2_ctrl_ref *ref;
    2328                 :            : 
    2329                 :          0 :         id -= V4L2_CID_PRIVATE_BASE;
    2330                 :          0 :         list_for_each_entry(ref, &hdl->ctrl_refs, node) {
    2331                 :            :                 /* Search for private user controls that are compatible with
    2332                 :            :                    VIDIOC_G/S_CTRL. */
    2333                 :          0 :                 if (V4L2_CTRL_ID2WHICH(ref->ctrl->id) == V4L2_CTRL_CLASS_USER &&
    2334                 :          0 :                     V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) {
    2335                 :          0 :                         if (!ref->ctrl->is_int)
    2336                 :          0 :                                 continue;
    2337                 :          0 :                         if (id == 0)
    2338                 :          0 :                                 return ref;
    2339                 :          0 :                         id--;
    2340                 :            :                 }
    2341                 :            :         }
    2342                 :            :         return NULL;
    2343                 :            : }
    2344                 :            : 
    2345                 :            : /* Find a control with the given ID. */
    2346                 :          3 : static struct v4l2_ctrl_ref *find_ref(struct v4l2_ctrl_handler *hdl, u32 id)
    2347                 :            : {
    2348                 :            :         struct v4l2_ctrl_ref *ref;
    2349                 :            :         int bucket;
    2350                 :            : 
    2351                 :          3 :         id &= V4L2_CTRL_ID_MASK;
    2352                 :            : 
    2353                 :            :         /* Old-style private controls need special handling */
    2354                 :          3 :         if (id >= V4L2_CID_PRIVATE_BASE)
    2355                 :          0 :                 return find_private_ref(hdl, id);
    2356                 :          3 :         bucket = id % hdl->nr_of_buckets;
    2357                 :            : 
    2358                 :            :         /* Simple optimization: cache the last control found */
    2359                 :          3 :         if (hdl->cached && hdl->cached->ctrl->id == id)
    2360                 :            :                 return hdl->cached;
    2361                 :            : 
    2362                 :            :         /* Not in cache, search the hash */
    2363                 :          3 :         ref = hdl->buckets ? hdl->buckets[bucket] : NULL;
    2364                 :          3 :         while (ref && ref->ctrl->id != id)
    2365                 :          3 :                 ref = ref->next;
    2366                 :            : 
    2367                 :          3 :         if (ref)
    2368                 :          3 :                 hdl->cached = ref; /* cache it! */
    2369                 :          3 :         return ref;
    2370                 :            : }
    2371                 :            : 
    2372                 :            : /* Find a control with the given ID. Take the handler's lock first. */
    2373                 :          3 : static struct v4l2_ctrl_ref *find_ref_lock(
    2374                 :            :                 struct v4l2_ctrl_handler *hdl, u32 id)
    2375                 :            : {
    2376                 :            :         struct v4l2_ctrl_ref *ref = NULL;
    2377                 :            : 
    2378                 :          3 :         if (hdl) {
    2379                 :          3 :                 mutex_lock(hdl->lock);
    2380                 :          3 :                 ref = find_ref(hdl, id);
    2381                 :          3 :                 mutex_unlock(hdl->lock);
    2382                 :            :         }
    2383                 :          3 :         return ref;
    2384                 :            : }
    2385                 :            : 
    2386                 :            : /* Find a control with the given ID. */
    2387                 :          0 : struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id)
    2388                 :            : {
    2389                 :          0 :         struct v4l2_ctrl_ref *ref = find_ref_lock(hdl, id);
    2390                 :            : 
    2391                 :          0 :         return ref ? ref->ctrl : NULL;
    2392                 :            : }
    2393                 :            : EXPORT_SYMBOL(v4l2_ctrl_find);
    2394                 :            : 
    2395                 :            : /* Allocate a new v4l2_ctrl_ref and hook it into the handler. */
    2396                 :          3 : static int handler_new_ref(struct v4l2_ctrl_handler *hdl,
    2397                 :            :                            struct v4l2_ctrl *ctrl,
    2398                 :            :                            struct v4l2_ctrl_ref **ctrl_ref,
    2399                 :            :                            bool from_other_dev, bool allocate_req)
    2400                 :            : {
    2401                 :            :         struct v4l2_ctrl_ref *ref;
    2402                 :            :         struct v4l2_ctrl_ref *new_ref;
    2403                 :          3 :         u32 id = ctrl->id;
    2404                 :          3 :         u32 class_ctrl = V4L2_CTRL_ID2WHICH(id) | 1;
    2405                 :          3 :         int bucket = id % hdl->nr_of_buckets;        /* which bucket to use */
    2406                 :            :         unsigned int size_extra_req = 0;
    2407                 :            : 
    2408                 :          3 :         if (ctrl_ref)
    2409                 :          0 :                 *ctrl_ref = NULL;
    2410                 :            : 
    2411                 :            :         /*
    2412                 :            :          * Automatically add the control class if it is not yet present and
    2413                 :            :          * the new control is not a compound control.
    2414                 :            :          */
    2415                 :          3 :         if (ctrl->type < V4L2_CTRL_COMPOUND_TYPES &&
    2416                 :          3 :             id != class_ctrl && find_ref_lock(hdl, class_ctrl) == NULL)
    2417                 :          3 :                 if (!v4l2_ctrl_new_std(hdl, NULL, class_ctrl, 0, 0, 0, 0))
    2418                 :          0 :                         return hdl->error;
    2419                 :            : 
    2420                 :          3 :         if (hdl->error)
    2421                 :            :                 return hdl->error;
    2422                 :            : 
    2423                 :          3 :         if (allocate_req)
    2424                 :          0 :                 size_extra_req = ctrl->elems * ctrl->elem_size;
    2425                 :          3 :         new_ref = kzalloc(sizeof(*new_ref) + size_extra_req, GFP_KERNEL);
    2426                 :          3 :         if (!new_ref)
    2427                 :            :                 return handler_set_err(hdl, -ENOMEM);
    2428                 :          3 :         new_ref->ctrl = ctrl;
    2429                 :          3 :         new_ref->from_other_dev = from_other_dev;
    2430                 :          3 :         if (size_extra_req)
    2431                 :          0 :                 new_ref->p_req.p = &new_ref[1];
    2432                 :            : 
    2433                 :          3 :         INIT_LIST_HEAD(&new_ref->node);
    2434                 :            : 
    2435                 :          3 :         mutex_lock(hdl->lock);
    2436                 :            : 
    2437                 :            :         /* Add immediately at the end of the list if the list is empty, or if
    2438                 :            :            the last element in the list has a lower ID.
    2439                 :            :            This ensures that when elements are added in ascending order the
    2440                 :            :            insertion is an O(1) operation. */
    2441                 :          3 :         if (list_empty(&hdl->ctrl_refs) || id > node2id(hdl->ctrl_refs.prev)) {
    2442                 :            :                 list_add_tail(&new_ref->node, &hdl->ctrl_refs);
    2443                 :            :                 goto insert_in_hash;
    2444                 :            :         }
    2445                 :            : 
    2446                 :            :         /* Find insert position in sorted list */
    2447                 :          3 :         list_for_each_entry(ref, &hdl->ctrl_refs, node) {
    2448                 :          3 :                 if (ref->ctrl->id < id)
    2449                 :          3 :                         continue;
    2450                 :            :                 /* Don't add duplicates */
    2451                 :          3 :                 if (ref->ctrl->id == id) {
    2452                 :          0 :                         kfree(new_ref);
    2453                 :          0 :                         goto unlock;
    2454                 :            :                 }
    2455                 :          3 :                 list_add(&new_ref->node, ref->node.prev);
    2456                 :            :                 break;
    2457                 :            :         }
    2458                 :            : 
    2459                 :            : insert_in_hash:
    2460                 :            :         /* Insert the control node in the hash */
    2461                 :          3 :         new_ref->next = hdl->buckets[bucket];
    2462                 :          3 :         hdl->buckets[bucket] = new_ref;
    2463                 :          3 :         if (ctrl_ref)
    2464                 :          0 :                 *ctrl_ref = new_ref;
    2465                 :          3 :         if (ctrl->handler == hdl) {
    2466                 :            :                 /* By default each control starts in a cluster of its own.
    2467                 :            :                  * new_ref->ctrl is basically a cluster array with one
    2468                 :            :                  * element, so that's perfect to use as the cluster pointer.
    2469                 :            :                  * But only do this for the handler that owns the control.
    2470                 :            :                  */
    2471                 :          3 :                 ctrl->cluster = &new_ref->ctrl;
    2472                 :          3 :                 ctrl->ncontrols = 1;
    2473                 :            :         }
    2474                 :            : 
    2475                 :            : unlock:
    2476                 :          3 :         mutex_unlock(hdl->lock);
    2477                 :          3 :         return 0;
    2478                 :            : }
    2479                 :            : 
    2480                 :            : /* Add a new control */
    2481                 :          3 : static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
    2482                 :            :                         const struct v4l2_ctrl_ops *ops,
    2483                 :            :                         const struct v4l2_ctrl_type_ops *type_ops,
    2484                 :            :                         u32 id, const char *name, enum v4l2_ctrl_type type,
    2485                 :            :                         s64 min, s64 max, u64 step, s64 def,
    2486                 :            :                         const u32 dims[V4L2_CTRL_MAX_DIMS], u32 elem_size,
    2487                 :            :                         u32 flags, const char * const *qmenu,
    2488                 :            :                         const s64 *qmenu_int, void *priv)
    2489                 :            : {
    2490                 :            :         struct v4l2_ctrl *ctrl;
    2491                 :            :         unsigned sz_extra;
    2492                 :            :         unsigned nr_of_dims = 0;
    2493                 :            :         unsigned elems = 1;
    2494                 :            :         bool is_array;
    2495                 :            :         unsigned tot_ctrl_size;
    2496                 :            :         unsigned idx;
    2497                 :            :         void *data;
    2498                 :            :         int err;
    2499                 :            : 
    2500                 :          3 :         if (hdl->error)
    2501                 :            :                 return NULL;
    2502                 :            : 
    2503                 :          3 :         while (dims && dims[nr_of_dims]) {
    2504                 :          3 :                 elems *= dims[nr_of_dims];
    2505                 :          3 :                 nr_of_dims++;
    2506                 :          3 :                 if (nr_of_dims == V4L2_CTRL_MAX_DIMS)
    2507                 :            :                         break;
    2508                 :            :         }
    2509                 :          3 :         is_array = nr_of_dims > 0;
    2510                 :            : 
    2511                 :            :         /* Prefill elem_size for all types handled by std_type_ops */
    2512                 :          3 :         switch ((u32)type) {
    2513                 :            :         case V4L2_CTRL_TYPE_INTEGER64:
    2514                 :            :                 elem_size = sizeof(s64);
    2515                 :            :                 break;
    2516                 :            :         case V4L2_CTRL_TYPE_STRING:
    2517                 :          0 :                 elem_size = max + 1;
    2518                 :          0 :                 break;
    2519                 :            :         case V4L2_CTRL_TYPE_U8:
    2520                 :            :                 elem_size = sizeof(u8);
    2521                 :          3 :                 break;
    2522                 :            :         case V4L2_CTRL_TYPE_U16:
    2523                 :            :                 elem_size = sizeof(u16);
    2524                 :          0 :                 break;
    2525                 :            :         case V4L2_CTRL_TYPE_U32:
    2526                 :            :                 elem_size = sizeof(u32);
    2527                 :          0 :                 break;
    2528                 :            :         case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
    2529                 :            :                 elem_size = sizeof(struct v4l2_ctrl_mpeg2_slice_params);
    2530                 :          0 :                 break;
    2531                 :            :         case V4L2_CTRL_TYPE_MPEG2_QUANTIZATION:
    2532                 :            :                 elem_size = sizeof(struct v4l2_ctrl_mpeg2_quantization);
    2533                 :          0 :                 break;
    2534                 :            :         case V4L2_CTRL_TYPE_FWHT_PARAMS:
    2535                 :            :                 elem_size = sizeof(struct v4l2_ctrl_fwht_params);
    2536                 :          0 :                 break;
    2537                 :            :         case V4L2_CTRL_TYPE_H264_SPS:
    2538                 :            :                 elem_size = sizeof(struct v4l2_ctrl_h264_sps);
    2539                 :          0 :                 break;
    2540                 :            :         case V4L2_CTRL_TYPE_H264_PPS:
    2541                 :            :                 elem_size = sizeof(struct v4l2_ctrl_h264_pps);
    2542                 :          0 :                 break;
    2543                 :            :         case V4L2_CTRL_TYPE_H264_SCALING_MATRIX:
    2544                 :            :                 elem_size = sizeof(struct v4l2_ctrl_h264_scaling_matrix);
    2545                 :          0 :                 break;
    2546                 :            :         case V4L2_CTRL_TYPE_H264_SLICE_PARAMS:
    2547                 :            :                 elem_size = sizeof(struct v4l2_ctrl_h264_slice_params);
    2548                 :          0 :                 break;
    2549                 :            :         case V4L2_CTRL_TYPE_H264_DECODE_PARAMS:
    2550                 :            :                 elem_size = sizeof(struct v4l2_ctrl_h264_decode_params);
    2551                 :          0 :                 break;
    2552                 :            :         case V4L2_CTRL_TYPE_VP8_FRAME_HEADER:
    2553                 :            :                 elem_size = sizeof(struct v4l2_ctrl_vp8_frame_header);
    2554                 :          0 :                 break;
    2555                 :            :         case V4L2_CTRL_TYPE_HEVC_SPS:
    2556                 :            :                 elem_size = sizeof(struct v4l2_ctrl_hevc_sps);
    2557                 :          0 :                 break;
    2558                 :            :         case V4L2_CTRL_TYPE_HEVC_PPS:
    2559                 :            :                 elem_size = sizeof(struct v4l2_ctrl_hevc_pps);
    2560                 :          0 :                 break;
    2561                 :            :         case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
    2562                 :            :                 elem_size = sizeof(struct v4l2_ctrl_hevc_slice_params);
    2563                 :          0 :                 break;
    2564                 :            :         case V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX:
    2565                 :            :                 elem_size = sizeof(struct v4l2_ctrl_hevc_scaling_matrix);
    2566                 :          0 :                 break;
    2567                 :            :         case V4L2_CTRL_TYPE_AREA:
    2568                 :            :                 elem_size = sizeof(struct v4l2_area);
    2569                 :            :                 break;
    2570                 :            :         default:
    2571                 :          3 :                 if (type < V4L2_CTRL_COMPOUND_TYPES)
    2572                 :            :                         elem_size = sizeof(s32);
    2573                 :            :                 break;
    2574                 :            :         }
    2575                 :          3 :         tot_ctrl_size = elem_size * elems;
    2576                 :            : 
    2577                 :            :         /* Sanity checks */
    2578                 :          3 :         if (id == 0 || name == NULL || !elem_size ||
    2579                 :          3 :             id >= V4L2_CID_PRIVATE_BASE ||
    2580                 :          3 :             (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) ||
    2581                 :          3 :             (type == V4L2_CTRL_TYPE_INTEGER_MENU && qmenu_int == NULL)) {
    2582                 :            :                 handler_set_err(hdl, -ERANGE);
    2583                 :            :                 return NULL;
    2584                 :            :         }
    2585                 :          3 :         err = check_range(type, min, max, step, def);
    2586                 :          3 :         if (err) {
    2587                 :            :                 handler_set_err(hdl, err);
    2588                 :            :                 return NULL;
    2589                 :            :         }
    2590                 :          3 :         if (is_array &&
    2591                 :          3 :             (type == V4L2_CTRL_TYPE_BUTTON ||
    2592                 :          3 :              type == V4L2_CTRL_TYPE_CTRL_CLASS)) {
    2593                 :            :                 handler_set_err(hdl, -EINVAL);
    2594                 :            :                 return NULL;
    2595                 :            :         }
    2596                 :            : 
    2597                 :            :         sz_extra = 0;
    2598                 :          3 :         if (type == V4L2_CTRL_TYPE_BUTTON)
    2599                 :          3 :                 flags |= V4L2_CTRL_FLAG_WRITE_ONLY |
    2600                 :            :                         V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
    2601                 :          3 :         else if (type == V4L2_CTRL_TYPE_CTRL_CLASS)
    2602                 :          3 :                 flags |= V4L2_CTRL_FLAG_READ_ONLY;
    2603                 :          3 :         else if (type == V4L2_CTRL_TYPE_INTEGER64 ||
    2604                 :          3 :                  type == V4L2_CTRL_TYPE_STRING ||
    2605                 :          3 :                  type >= V4L2_CTRL_COMPOUND_TYPES ||
    2606                 :            :                  is_array)
    2607                 :          3 :                 sz_extra += 2 * tot_ctrl_size;
    2608                 :            : 
    2609                 :          3 :         ctrl = kvzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL);
    2610                 :          3 :         if (ctrl == NULL) {
    2611                 :            :                 handler_set_err(hdl, -ENOMEM);
    2612                 :            :                 return NULL;
    2613                 :            :         }
    2614                 :            : 
    2615                 :          3 :         INIT_LIST_HEAD(&ctrl->node);
    2616                 :          3 :         INIT_LIST_HEAD(&ctrl->ev_subs);
    2617                 :          3 :         ctrl->handler = hdl;
    2618                 :          3 :         ctrl->ops = ops;
    2619                 :          3 :         ctrl->type_ops = type_ops ? type_ops : &std_type_ops;
    2620                 :          3 :         ctrl->id = id;
    2621                 :          3 :         ctrl->name = name;
    2622                 :          3 :         ctrl->type = type;
    2623                 :          3 :         ctrl->flags = flags;
    2624                 :          3 :         ctrl->minimum = min;
    2625                 :          3 :         ctrl->maximum = max;
    2626                 :          3 :         ctrl->step = step;
    2627                 :          3 :         ctrl->default_value = def;
    2628                 :          3 :         ctrl->is_string = !is_array && type == V4L2_CTRL_TYPE_STRING;
    2629                 :          3 :         ctrl->is_ptr = is_array || type >= V4L2_CTRL_COMPOUND_TYPES || ctrl->is_string;
    2630                 :          3 :         ctrl->is_int = !ctrl->is_ptr && type != V4L2_CTRL_TYPE_INTEGER64;
    2631                 :          3 :         ctrl->is_array = is_array;
    2632                 :          3 :         ctrl->elems = elems;
    2633                 :          3 :         ctrl->nr_of_dims = nr_of_dims;
    2634                 :          3 :         if (nr_of_dims)
    2635                 :          3 :                 memcpy(ctrl->dims, dims, nr_of_dims * sizeof(dims[0]));
    2636                 :          3 :         ctrl->elem_size = elem_size;
    2637                 :          3 :         if (type == V4L2_CTRL_TYPE_MENU)
    2638                 :          3 :                 ctrl->qmenu = qmenu;
    2639                 :          3 :         else if (type == V4L2_CTRL_TYPE_INTEGER_MENU)
    2640                 :          0 :                 ctrl->qmenu_int = qmenu_int;
    2641                 :          3 :         ctrl->priv = priv;
    2642                 :          3 :         ctrl->cur.val = ctrl->val = def;
    2643                 :          3 :         data = &ctrl[1];
    2644                 :            : 
    2645                 :          3 :         if (!ctrl->is_int) {
    2646                 :          3 :                 ctrl->p_new.p = data;
    2647                 :          3 :                 ctrl->p_cur.p = data + tot_ctrl_size;
    2648                 :            :         } else {
    2649                 :          3 :                 ctrl->p_new.p = &ctrl->val;
    2650                 :          3 :                 ctrl->p_cur.p = &ctrl->cur.val;
    2651                 :            :         }
    2652                 :          3 :         for (idx = 0; idx < elems; idx++) {
    2653                 :          3 :                 ctrl->type_ops->init(ctrl, idx, ctrl->p_cur);
    2654                 :          3 :                 ctrl->type_ops->init(ctrl, idx, ctrl->p_new);
    2655                 :            :         }
    2656                 :            : 
    2657                 :          3 :         if (handler_new_ref(hdl, ctrl, NULL, false, false)) {
    2658                 :          0 :                 kvfree(ctrl);
    2659                 :          0 :                 return NULL;
    2660                 :            :         }
    2661                 :          3 :         mutex_lock(hdl->lock);
    2662                 :          3 :         list_add_tail(&ctrl->node, &hdl->ctrls);
    2663                 :          3 :         mutex_unlock(hdl->lock);
    2664                 :          3 :         return ctrl;
    2665                 :            : }
    2666                 :            : 
    2667                 :          3 : struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
    2668                 :            :                         const struct v4l2_ctrl_config *cfg, void *priv)
    2669                 :            : {
    2670                 :            :         bool is_menu;
    2671                 :            :         struct v4l2_ctrl *ctrl;
    2672                 :          3 :         const char *name = cfg->name;
    2673                 :          3 :         const char * const *qmenu = cfg->qmenu;
    2674                 :          3 :         const s64 *qmenu_int = cfg->qmenu_int;
    2675                 :          3 :         enum v4l2_ctrl_type type = cfg->type;
    2676                 :          3 :         u32 flags = cfg->flags;
    2677                 :          3 :         s64 min = cfg->min;
    2678                 :          3 :         s64 max = cfg->max;
    2679                 :          3 :         u64 step = cfg->step;
    2680                 :          3 :         s64 def = cfg->def;
    2681                 :            : 
    2682                 :          3 :         if (name == NULL)
    2683                 :          0 :                 v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step,
    2684                 :            :                                                                 &def, &flags);
    2685                 :            : 
    2686                 :          3 :         is_menu = (type == V4L2_CTRL_TYPE_MENU ||
    2687                 :            :                    type == V4L2_CTRL_TYPE_INTEGER_MENU);
    2688                 :          3 :         if (is_menu)
    2689                 :          0 :                 WARN_ON(step);
    2690                 :            :         else
    2691                 :          3 :                 WARN_ON(cfg->menu_skip_mask);
    2692                 :          3 :         if (type == V4L2_CTRL_TYPE_MENU && !qmenu) {
    2693                 :          0 :                 qmenu = v4l2_ctrl_get_menu(cfg->id);
    2694                 :          3 :         } else if (type == V4L2_CTRL_TYPE_INTEGER_MENU && !qmenu_int) {
    2695                 :            :                 handler_set_err(hdl, -EINVAL);
    2696                 :            :                 return NULL;
    2697                 :            :         }
    2698                 :            : 
    2699                 :          3 :         ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->type_ops, cfg->id, name,
    2700                 :            :                         type, min, max,
    2701                 :            :                         is_menu ? cfg->menu_skip_mask : step, def,
    2702                 :          3 :                         cfg->dims, cfg->elem_size,
    2703                 :            :                         flags, qmenu, qmenu_int, priv);
    2704                 :          3 :         if (ctrl)
    2705                 :          3 :                 ctrl->is_private = cfg->is_private;
    2706                 :          3 :         return ctrl;
    2707                 :            : }
    2708                 :            : EXPORT_SYMBOL(v4l2_ctrl_new_custom);
    2709                 :            : 
    2710                 :            : /* Helper function for standard non-menu controls */
    2711                 :          3 : struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
    2712                 :            :                         const struct v4l2_ctrl_ops *ops,
    2713                 :            :                         u32 id, s64 min, s64 max, u64 step, s64 def)
    2714                 :            : {
    2715                 :            :         const char *name;
    2716                 :            :         enum v4l2_ctrl_type type;
    2717                 :            :         u32 flags;
    2718                 :            : 
    2719                 :          3 :         v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
    2720                 :          3 :         if (type == V4L2_CTRL_TYPE_MENU ||
    2721                 :          3 :             type == V4L2_CTRL_TYPE_INTEGER_MENU ||
    2722                 :            :             type >= V4L2_CTRL_COMPOUND_TYPES) {
    2723                 :            :                 handler_set_err(hdl, -EINVAL);
    2724                 :            :                 return NULL;
    2725                 :            :         }
    2726                 :          3 :         return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
    2727                 :            :                              min, max, step, def, NULL, 0,
    2728                 :            :                              flags, NULL, NULL, NULL);
    2729                 :            : }
    2730                 :            : EXPORT_SYMBOL(v4l2_ctrl_new_std);
    2731                 :            : 
    2732                 :            : /* Helper function for standard menu controls */
    2733                 :          3 : struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
    2734                 :            :                         const struct v4l2_ctrl_ops *ops,
    2735                 :            :                         u32 id, u8 _max, u64 mask, u8 _def)
    2736                 :            : {
    2737                 :            :         const char * const *qmenu = NULL;
    2738                 :            :         const s64 *qmenu_int = NULL;
    2739                 :            :         unsigned int qmenu_int_len = 0;
    2740                 :            :         const char *name;
    2741                 :            :         enum v4l2_ctrl_type type;
    2742                 :            :         s64 min;
    2743                 :          3 :         s64 max = _max;
    2744                 :          3 :         s64 def = _def;
    2745                 :            :         u64 step;
    2746                 :            :         u32 flags;
    2747                 :            : 
    2748                 :          3 :         v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
    2749                 :            : 
    2750                 :          3 :         if (type == V4L2_CTRL_TYPE_MENU)
    2751                 :          3 :                 qmenu = v4l2_ctrl_get_menu(id);
    2752                 :          0 :         else if (type == V4L2_CTRL_TYPE_INTEGER_MENU)
    2753                 :            :                 qmenu_int = v4l2_ctrl_get_int_menu(id, &qmenu_int_len);
    2754                 :            : 
    2755                 :          3 :         if ((!qmenu && !qmenu_int) || (qmenu_int && max > qmenu_int_len)) {
    2756                 :            :                 handler_set_err(hdl, -EINVAL);
    2757                 :            :                 return NULL;
    2758                 :            :         }
    2759                 :          3 :         return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
    2760                 :            :                              0, max, mask, def, NULL, 0,
    2761                 :            :                              flags, qmenu, qmenu_int, NULL);
    2762                 :            : }
    2763                 :            : EXPORT_SYMBOL(v4l2_ctrl_new_std_menu);
    2764                 :            : 
    2765                 :            : /* Helper function for standard menu controls with driver defined menu */
    2766                 :          0 : struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
    2767                 :            :                         const struct v4l2_ctrl_ops *ops, u32 id, u8 _max,
    2768                 :            :                         u64 mask, u8 _def, const char * const *qmenu)
    2769                 :            : {
    2770                 :            :         enum v4l2_ctrl_type type;
    2771                 :            :         const char *name;
    2772                 :            :         u32 flags;
    2773                 :            :         u64 step;
    2774                 :            :         s64 min;
    2775                 :          0 :         s64 max = _max;
    2776                 :          0 :         s64 def = _def;
    2777                 :            : 
    2778                 :            :         /* v4l2_ctrl_new_std_menu_items() should only be called for
    2779                 :            :          * standard controls without a standard menu.
    2780                 :            :          */
    2781                 :          0 :         if (v4l2_ctrl_get_menu(id)) {
    2782                 :            :                 handler_set_err(hdl, -EINVAL);
    2783                 :            :                 return NULL;
    2784                 :            :         }
    2785                 :            : 
    2786                 :          0 :         v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
    2787                 :          0 :         if (type != V4L2_CTRL_TYPE_MENU || qmenu == NULL) {
    2788                 :            :                 handler_set_err(hdl, -EINVAL);
    2789                 :            :                 return NULL;
    2790                 :            :         }
    2791                 :          0 :         return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
    2792                 :            :                              0, max, mask, def, NULL, 0,
    2793                 :            :                              flags, qmenu, NULL, NULL);
    2794                 :            : 
    2795                 :            : }
    2796                 :            : EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items);
    2797                 :            : 
    2798                 :            : /* Helper function for standard integer menu controls */
    2799                 :          0 : struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
    2800                 :            :                         const struct v4l2_ctrl_ops *ops,
    2801                 :            :                         u32 id, u8 _max, u8 _def, const s64 *qmenu_int)
    2802                 :            : {
    2803                 :            :         const char *name;
    2804                 :            :         enum v4l2_ctrl_type type;
    2805                 :            :         s64 min;
    2806                 :            :         u64 step;
    2807                 :          0 :         s64 max = _max;
    2808                 :          0 :         s64 def = _def;
    2809                 :            :         u32 flags;
    2810                 :            : 
    2811                 :          0 :         v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
    2812                 :          0 :         if (type != V4L2_CTRL_TYPE_INTEGER_MENU) {
    2813                 :            :                 handler_set_err(hdl, -EINVAL);
    2814                 :            :                 return NULL;
    2815                 :            :         }
    2816                 :          0 :         return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
    2817                 :            :                              0, max, 0, def, NULL, 0,
    2818                 :            :                              flags, NULL, qmenu_int, NULL);
    2819                 :            : }
    2820                 :            : EXPORT_SYMBOL(v4l2_ctrl_new_int_menu);
    2821                 :            : 
    2822                 :            : /* Add the controls from another handler to our own. */
    2823                 :          0 : int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
    2824                 :            :                           struct v4l2_ctrl_handler *add,
    2825                 :            :                           bool (*filter)(const struct v4l2_ctrl *ctrl),
    2826                 :            :                           bool from_other_dev)
    2827                 :            : {
    2828                 :            :         struct v4l2_ctrl_ref *ref;
    2829                 :            :         int ret = 0;
    2830                 :            : 
    2831                 :            :         /* Do nothing if either handler is NULL or if they are the same */
    2832                 :          0 :         if (!hdl || !add || hdl == add)
    2833                 :            :                 return 0;
    2834                 :          0 :         if (hdl->error)
    2835                 :            :                 return hdl->error;
    2836                 :          0 :         mutex_lock(add->lock);
    2837                 :          0 :         list_for_each_entry(ref, &add->ctrl_refs, node) {
    2838                 :          0 :                 struct v4l2_ctrl *ctrl = ref->ctrl;
    2839                 :            : 
    2840                 :            :                 /* Skip handler-private controls. */
    2841                 :          0 :                 if (ctrl->is_private)
    2842                 :          0 :                         continue;
    2843                 :            :                 /* And control classes */
    2844                 :          0 :                 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
    2845                 :          0 :                         continue;
    2846                 :            :                 /* Filter any unwanted controls */
    2847                 :          0 :                 if (filter && !filter(ctrl))
    2848                 :          0 :                         continue;
    2849                 :          0 :                 ret = handler_new_ref(hdl, ctrl, NULL, from_other_dev, false);
    2850                 :          0 :                 if (ret)
    2851                 :            :                         break;
    2852                 :            :         }
    2853                 :          0 :         mutex_unlock(add->lock);
    2854                 :          0 :         return ret;
    2855                 :            : }
    2856                 :            : EXPORT_SYMBOL(v4l2_ctrl_add_handler);
    2857                 :            : 
    2858                 :          0 : bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl)
    2859                 :            : {
    2860                 :          0 :         if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_TX)
    2861                 :            :                 return true;
    2862                 :          0 :         if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_RX)
    2863                 :            :                 return true;
    2864                 :          0 :         switch (ctrl->id) {
    2865                 :            :         case V4L2_CID_AUDIO_MUTE:
    2866                 :            :         case V4L2_CID_AUDIO_VOLUME:
    2867                 :            :         case V4L2_CID_AUDIO_BALANCE:
    2868                 :            :         case V4L2_CID_AUDIO_BASS:
    2869                 :            :         case V4L2_CID_AUDIO_TREBLE:
    2870                 :            :         case V4L2_CID_AUDIO_LOUDNESS:
    2871                 :            :                 return true;
    2872                 :            :         default:
    2873                 :            :                 break;
    2874                 :            :         }
    2875                 :          0 :         return false;
    2876                 :            : }
    2877                 :            : EXPORT_SYMBOL(v4l2_ctrl_radio_filter);
    2878                 :            : 
    2879                 :            : /* Cluster controls */
    2880                 :          0 : void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls)
    2881                 :            : {
    2882                 :            :         bool has_volatiles = false;
    2883                 :            :         int i;
    2884                 :            : 
    2885                 :            :         /* The first control is the master control and it must not be NULL */
    2886                 :          0 :         if (WARN_ON(ncontrols == 0 || controls[0] == NULL))
    2887                 :          0 :                 return;
    2888                 :            : 
    2889                 :          0 :         for (i = 0; i < ncontrols; i++) {
    2890                 :          0 :                 if (controls[i]) {
    2891                 :          0 :                         controls[i]->cluster = controls;
    2892                 :          0 :                         controls[i]->ncontrols = ncontrols;
    2893                 :          0 :                         if (controls[i]->flags & V4L2_CTRL_FLAG_VOLATILE)
    2894                 :            :                                 has_volatiles = true;
    2895                 :            :                 }
    2896                 :            :         }
    2897                 :          0 :         controls[0]->has_volatiles = has_volatiles;
    2898                 :            : }
    2899                 :            : EXPORT_SYMBOL(v4l2_ctrl_cluster);
    2900                 :            : 
    2901                 :          0 : void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls,
    2902                 :            :                             u8 manual_val, bool set_volatile)
    2903                 :            : {
    2904                 :          0 :         struct v4l2_ctrl *master = controls[0];
    2905                 :            :         u32 flag = 0;
    2906                 :            :         int i;
    2907                 :            : 
    2908                 :          0 :         v4l2_ctrl_cluster(ncontrols, controls);
    2909                 :          0 :         WARN_ON(ncontrols <= 1);
    2910                 :          0 :         WARN_ON(manual_val < master->minimum || manual_val > master->maximum);
    2911                 :          0 :         WARN_ON(set_volatile && !has_op(master, g_volatile_ctrl));
    2912                 :          0 :         master->is_auto = true;
    2913                 :          0 :         master->has_volatiles = set_volatile;
    2914                 :          0 :         master->manual_mode_value = manual_val;
    2915                 :          0 :         master->flags |= V4L2_CTRL_FLAG_UPDATE;
    2916                 :            : 
    2917                 :          0 :         if (!is_cur_manual(master))
    2918                 :          0 :                 flag = V4L2_CTRL_FLAG_INACTIVE |
    2919                 :            :                         (set_volatile ? V4L2_CTRL_FLAG_VOLATILE : 0);
    2920                 :            : 
    2921                 :          0 :         for (i = 1; i < ncontrols; i++)
    2922                 :          0 :                 if (controls[i])
    2923                 :          0 :                         controls[i]->flags |= flag;
    2924                 :          0 : }
    2925                 :            : EXPORT_SYMBOL(v4l2_ctrl_auto_cluster);
    2926                 :            : 
    2927                 :            : /* Activate/deactivate a control. */
    2928                 :          0 : void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active)
    2929                 :            : {
    2930                 :            :         /* invert since the actual flag is called 'inactive' */
    2931                 :          0 :         bool inactive = !active;
    2932                 :            :         bool old;
    2933                 :            : 
    2934                 :          0 :         if (ctrl == NULL)
    2935                 :          0 :                 return;
    2936                 :            : 
    2937                 :          0 :         if (inactive)
    2938                 :            :                 /* set V4L2_CTRL_FLAG_INACTIVE */
    2939                 :          0 :                 old = test_and_set_bit(4, &ctrl->flags);
    2940                 :            :         else
    2941                 :            :                 /* clear V4L2_CTRL_FLAG_INACTIVE */
    2942                 :          0 :                 old = test_and_clear_bit(4, &ctrl->flags);
    2943                 :          0 :         if (old != inactive)
    2944                 :          0 :                 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS);
    2945                 :            : }
    2946                 :            : EXPORT_SYMBOL(v4l2_ctrl_activate);
    2947                 :            : 
    2948                 :          0 : void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
    2949                 :            : {
    2950                 :            :         bool old;
    2951                 :            : 
    2952                 :          0 :         if (ctrl == NULL)
    2953                 :          0 :                 return;
    2954                 :            : 
    2955                 :            :         lockdep_assert_held(ctrl->handler->lock);
    2956                 :            : 
    2957                 :          0 :         if (grabbed)
    2958                 :            :                 /* set V4L2_CTRL_FLAG_GRABBED */
    2959                 :          0 :                 old = test_and_set_bit(1, &ctrl->flags);
    2960                 :            :         else
    2961                 :            :                 /* clear V4L2_CTRL_FLAG_GRABBED */
    2962                 :          0 :                 old = test_and_clear_bit(1, &ctrl->flags);
    2963                 :          0 :         if (old != grabbed)
    2964                 :          0 :                 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS);
    2965                 :            : }
    2966                 :            : EXPORT_SYMBOL(__v4l2_ctrl_grab);
    2967                 :            : 
    2968                 :            : /* Log the control name and value */
    2969                 :          0 : static void log_ctrl(const struct v4l2_ctrl *ctrl,
    2970                 :            :                      const char *prefix, const char *colon)
    2971                 :            : {
    2972                 :          0 :         if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY))
    2973                 :            :                 return;
    2974                 :          0 :         if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
    2975                 :            :                 return;
    2976                 :            : 
    2977                 :          0 :         pr_info("%s%s%s: ", prefix, colon, ctrl->name);
    2978                 :            : 
    2979                 :          0 :         ctrl->type_ops->log(ctrl);
    2980                 :            : 
    2981                 :          0 :         if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE |
    2982                 :            :                            V4L2_CTRL_FLAG_GRABBED |
    2983                 :            :                            V4L2_CTRL_FLAG_VOLATILE)) {
    2984                 :          0 :                 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
    2985                 :          0 :                         pr_cont(" inactive");
    2986                 :          0 :                 if (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)
    2987                 :          0 :                         pr_cont(" grabbed");
    2988                 :          0 :                 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE)
    2989                 :          0 :                         pr_cont(" volatile");
    2990                 :            :         }
    2991                 :          0 :         pr_cont("\n");
    2992                 :            : }
    2993                 :            : 
    2994                 :            : /* Log all controls owned by the handler */
    2995                 :          0 : void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
    2996                 :            :                                   const char *prefix)
    2997                 :            : {
    2998                 :            :         struct v4l2_ctrl *ctrl;
    2999                 :            :         const char *colon = "";
    3000                 :            :         int len;
    3001                 :            : 
    3002                 :          0 :         if (hdl == NULL)
    3003                 :          0 :                 return;
    3004                 :          0 :         if (prefix == NULL)
    3005                 :            :                 prefix = "";
    3006                 :          0 :         len = strlen(prefix);
    3007                 :          0 :         if (len && prefix[len - 1] != ' ')
    3008                 :            :                 colon = ": ";
    3009                 :          0 :         mutex_lock(hdl->lock);
    3010                 :          0 :         list_for_each_entry(ctrl, &hdl->ctrls, node)
    3011                 :          0 :                 if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED))
    3012                 :          0 :                         log_ctrl(ctrl, prefix, colon);
    3013                 :          0 :         mutex_unlock(hdl->lock);
    3014                 :            : }
    3015                 :            : EXPORT_SYMBOL(v4l2_ctrl_handler_log_status);
    3016                 :            : 
    3017                 :          0 : int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd)
    3018                 :            : {
    3019                 :          0 :         v4l2_ctrl_handler_log_status(sd->ctrl_handler, sd->name);
    3020                 :          0 :         return 0;
    3021                 :            : }
    3022                 :            : EXPORT_SYMBOL(v4l2_ctrl_subdev_log_status);
    3023                 :            : 
    3024                 :            : /* Call s_ctrl for all controls owned by the handler */
    3025                 :          3 : int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
    3026                 :            : {
    3027                 :            :         struct v4l2_ctrl *ctrl;
    3028                 :            :         int ret = 0;
    3029                 :            : 
    3030                 :          3 :         if (hdl == NULL)
    3031                 :            :                 return 0;
    3032                 :            : 
    3033                 :            :         lockdep_assert_held(hdl->lock);
    3034                 :            : 
    3035                 :          3 :         list_for_each_entry(ctrl, &hdl->ctrls, node)
    3036                 :          3 :                 ctrl->done = false;
    3037                 :            : 
    3038                 :          3 :         list_for_each_entry(ctrl, &hdl->ctrls, node) {
    3039                 :          3 :                 struct v4l2_ctrl *master = ctrl->cluster[0];
    3040                 :            :                 int i;
    3041                 :            : 
    3042                 :            :                 /* Skip if this control was already handled by a cluster. */
    3043                 :            :                 /* Skip button controls and read-only controls. */
    3044                 :          3 :                 if (ctrl->done || ctrl->type == V4L2_CTRL_TYPE_BUTTON ||
    3045                 :          3 :                     (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY))
    3046                 :          3 :                         continue;
    3047                 :            : 
    3048                 :          3 :                 for (i = 0; i < master->ncontrols; i++) {
    3049                 :          3 :                         if (master->cluster[i]) {
    3050                 :          3 :                                 cur_to_new(master->cluster[i]);
    3051                 :          3 :                                 master->cluster[i]->is_new = 1;
    3052                 :          3 :                                 master->cluster[i]->done = true;
    3053                 :            :                         }
    3054                 :            :                 }
    3055                 :          3 :                 ret = call_op(master, s_ctrl);
    3056                 :          3 :                 if (ret)
    3057                 :            :                         break;
    3058                 :            :         }
    3059                 :            : 
    3060                 :          3 :         return ret;
    3061                 :            : }
    3062                 :            : EXPORT_SYMBOL_GPL(__v4l2_ctrl_handler_setup);
    3063                 :            : 
    3064                 :          3 : int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
    3065                 :            : {
    3066                 :            :         int ret;
    3067                 :            : 
    3068                 :          3 :         if (hdl == NULL)
    3069                 :            :                 return 0;
    3070                 :            : 
    3071                 :          3 :         mutex_lock(hdl->lock);
    3072                 :          3 :         ret = __v4l2_ctrl_handler_setup(hdl);
    3073                 :          3 :         mutex_unlock(hdl->lock);
    3074                 :            : 
    3075                 :          3 :         return ret;
    3076                 :            : }
    3077                 :            : EXPORT_SYMBOL(v4l2_ctrl_handler_setup);
    3078                 :            : 
    3079                 :            : /* Implement VIDIOC_QUERY_EXT_CTRL */
    3080                 :          0 : int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctrl *qc)
    3081                 :            : {
    3082                 :            :         const unsigned next_flags = V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND;
    3083                 :          0 :         u32 id = qc->id & V4L2_CTRL_ID_MASK;
    3084                 :            :         struct v4l2_ctrl_ref *ref;
    3085                 :            :         struct v4l2_ctrl *ctrl;
    3086                 :            : 
    3087                 :          0 :         if (hdl == NULL)
    3088                 :            :                 return -EINVAL;
    3089                 :            : 
    3090                 :          0 :         mutex_lock(hdl->lock);
    3091                 :            : 
    3092                 :            :         /* Try to find it */
    3093                 :          0 :         ref = find_ref(hdl, id);
    3094                 :            : 
    3095                 :          0 :         if ((qc->id & next_flags) && !list_empty(&hdl->ctrl_refs)) {
    3096                 :            :                 bool is_compound;
    3097                 :            :                 /* Match any control that is not hidden */
    3098                 :            :                 unsigned mask = 1;
    3099                 :            :                 bool match = false;
    3100                 :            : 
    3101                 :          0 :                 if ((qc->id & next_flags) == V4L2_CTRL_FLAG_NEXT_COMPOUND) {
    3102                 :            :                         /* Match any hidden control */
    3103                 :            :                         match = true;
    3104                 :          0 :                 } else if ((qc->id & next_flags) == next_flags) {
    3105                 :            :                         /* Match any control, compound or not */
    3106                 :            :                         mask = 0;
    3107                 :            :                 }
    3108                 :            : 
    3109                 :            :                 /* Find the next control with ID > qc->id */
    3110                 :            : 
    3111                 :            :                 /* Did we reach the end of the control list? */
    3112                 :          0 :                 if (id >= node2id(hdl->ctrl_refs.prev)) {
    3113                 :            :                         ref = NULL; /* Yes, so there is no next control */
    3114                 :          0 :                 } else if (ref) {
    3115                 :            :                         /* We found a control with the given ID, so just get
    3116                 :            :                            the next valid one in the list. */
    3117                 :          0 :                         list_for_each_entry_continue(ref, &hdl->ctrl_refs, node) {
    3118                 :          0 :                                 is_compound = ref->ctrl->is_array ||
    3119                 :          0 :                                         ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
    3120                 :          0 :                                 if (id < ref->ctrl->id &&
    3121                 :          0 :                                     (is_compound & mask) == match)
    3122                 :            :                                         break;
    3123                 :            :                         }
    3124                 :          0 :                         if (&ref->node == &hdl->ctrl_refs)
    3125                 :            :                                 ref = NULL;
    3126                 :            :                 } else {
    3127                 :            :                         /* No control with the given ID exists, so start
    3128                 :            :                            searching for the next largest ID. We know there
    3129                 :            :                            is one, otherwise the first 'if' above would have
    3130                 :            :                            been true. */
    3131                 :          0 :                         list_for_each_entry(ref, &hdl->ctrl_refs, node) {
    3132                 :          0 :                                 is_compound = ref->ctrl->is_array ||
    3133                 :          0 :                                         ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
    3134                 :          0 :                                 if (id < ref->ctrl->id &&
    3135                 :          0 :                                     (is_compound & mask) == match)
    3136                 :            :                                         break;
    3137                 :            :                         }
    3138                 :          0 :                         if (&ref->node == &hdl->ctrl_refs)
    3139                 :            :                                 ref = NULL;
    3140                 :            :                 }
    3141                 :            :         }
    3142                 :          0 :         mutex_unlock(hdl->lock);
    3143                 :            : 
    3144                 :          0 :         if (!ref)
    3145                 :            :                 return -EINVAL;
    3146                 :            : 
    3147                 :          0 :         ctrl = ref->ctrl;
    3148                 :          0 :         memset(qc, 0, sizeof(*qc));
    3149                 :          0 :         if (id >= V4L2_CID_PRIVATE_BASE)
    3150                 :          0 :                 qc->id = id;
    3151                 :            :         else
    3152                 :          0 :                 qc->id = ctrl->id;
    3153                 :          0 :         strscpy(qc->name, ctrl->name, sizeof(qc->name));
    3154                 :          0 :         qc->flags = user_flags(ctrl);
    3155                 :          0 :         qc->type = ctrl->type;
    3156                 :          0 :         qc->elem_size = ctrl->elem_size;
    3157                 :          0 :         qc->elems = ctrl->elems;
    3158                 :          0 :         qc->nr_of_dims = ctrl->nr_of_dims;
    3159                 :          0 :         memcpy(qc->dims, ctrl->dims, qc->nr_of_dims * sizeof(qc->dims[0]));
    3160                 :          0 :         qc->minimum = ctrl->minimum;
    3161                 :          0 :         qc->maximum = ctrl->maximum;
    3162                 :          0 :         qc->default_value = ctrl->default_value;
    3163                 :          0 :         if (ctrl->type == V4L2_CTRL_TYPE_MENU
    3164                 :          0 :             || ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU)
    3165                 :          0 :                 qc->step = 1;
    3166                 :            :         else
    3167                 :          0 :                 qc->step = ctrl->step;
    3168                 :            :         return 0;
    3169                 :            : }
    3170                 :            : EXPORT_SYMBOL(v4l2_query_ext_ctrl);
    3171                 :            : 
    3172                 :            : /* Implement VIDIOC_QUERYCTRL */
    3173                 :          0 : int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc)
    3174                 :            : {
    3175                 :          0 :         struct v4l2_query_ext_ctrl qec = { qc->id };
    3176                 :            :         int rc;
    3177                 :            : 
    3178                 :          0 :         rc = v4l2_query_ext_ctrl(hdl, &qec);
    3179                 :          0 :         if (rc)
    3180                 :            :                 return rc;
    3181                 :            : 
    3182                 :          0 :         qc->id = qec.id;
    3183                 :          0 :         qc->type = qec.type;
    3184                 :          0 :         qc->flags = qec.flags;
    3185                 :          0 :         strscpy(qc->name, qec.name, sizeof(qc->name));
    3186                 :          0 :         switch (qc->type) {
    3187                 :            :         case V4L2_CTRL_TYPE_INTEGER:
    3188                 :            :         case V4L2_CTRL_TYPE_BOOLEAN:
    3189                 :            :         case V4L2_CTRL_TYPE_MENU:
    3190                 :            :         case V4L2_CTRL_TYPE_INTEGER_MENU:
    3191                 :            :         case V4L2_CTRL_TYPE_STRING:
    3192                 :            :         case V4L2_CTRL_TYPE_BITMASK:
    3193                 :          0 :                 qc->minimum = qec.minimum;
    3194                 :          0 :                 qc->maximum = qec.maximum;
    3195                 :          0 :                 qc->step = qec.step;
    3196                 :          0 :                 qc->default_value = qec.default_value;
    3197                 :          0 :                 break;
    3198                 :            :         default:
    3199                 :          0 :                 qc->minimum = 0;
    3200                 :          0 :                 qc->maximum = 0;
    3201                 :          0 :                 qc->step = 0;
    3202                 :          0 :                 qc->default_value = 0;
    3203                 :          0 :                 break;
    3204                 :            :         }
    3205                 :            :         return 0;
    3206                 :            : }
    3207                 :            : EXPORT_SYMBOL(v4l2_queryctrl);
    3208                 :            : 
    3209                 :            : /* Implement VIDIOC_QUERYMENU */
    3210                 :          0 : int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm)
    3211                 :            : {
    3212                 :            :         struct v4l2_ctrl *ctrl;
    3213                 :          0 :         u32 i = qm->index;
    3214                 :            : 
    3215                 :          0 :         ctrl = v4l2_ctrl_find(hdl, qm->id);
    3216                 :          0 :         if (!ctrl)
    3217                 :            :                 return -EINVAL;
    3218                 :            : 
    3219                 :          0 :         qm->reserved = 0;
    3220                 :            :         /* Sanity checks */
    3221                 :          0 :         switch (ctrl->type) {
    3222                 :            :         case V4L2_CTRL_TYPE_MENU:
    3223                 :          0 :                 if (ctrl->qmenu == NULL)
    3224                 :            :                         return -EINVAL;
    3225                 :            :                 break;
    3226                 :            :         case V4L2_CTRL_TYPE_INTEGER_MENU:
    3227                 :          0 :                 if (ctrl->qmenu_int == NULL)
    3228                 :            :                         return -EINVAL;
    3229                 :            :                 break;
    3230                 :            :         default:
    3231                 :            :                 return -EINVAL;
    3232                 :            :         }
    3233                 :            : 
    3234                 :          0 :         if (i < ctrl->minimum || i > ctrl->maximum)
    3235                 :            :                 return -EINVAL;
    3236                 :            : 
    3237                 :            :         /* Use mask to see if this menu item should be skipped */
    3238                 :          0 :         if (ctrl->menu_skip_mask & (1ULL << i))
    3239                 :            :                 return -EINVAL;
    3240                 :            :         /* Empty menu items should also be skipped */
    3241                 :          0 :         if (ctrl->type == V4L2_CTRL_TYPE_MENU) {
    3242                 :          0 :                 if (ctrl->qmenu[i] == NULL || ctrl->qmenu[i][0] == '\0')
    3243                 :            :                         return -EINVAL;
    3244                 :          0 :                 strscpy(qm->name, ctrl->qmenu[i], sizeof(qm->name));
    3245                 :            :         } else {
    3246                 :          0 :                 qm->value = ctrl->qmenu_int[i];
    3247                 :            :         }
    3248                 :            :         return 0;
    3249                 :            : }
    3250                 :            : EXPORT_SYMBOL(v4l2_querymenu);
    3251                 :            : 
    3252                 :          0 : static int v4l2_ctrl_request_clone(struct v4l2_ctrl_handler *hdl,
    3253                 :            :                                    const struct v4l2_ctrl_handler *from)
    3254                 :            : {
    3255                 :            :         struct v4l2_ctrl_ref *ref;
    3256                 :            :         int err = 0;
    3257                 :            : 
    3258                 :          0 :         if (WARN_ON(!hdl || hdl == from))
    3259                 :            :                 return -EINVAL;
    3260                 :            : 
    3261                 :          0 :         if (hdl->error)
    3262                 :            :                 return hdl->error;
    3263                 :            : 
    3264                 :          0 :         WARN_ON(hdl->lock != &hdl->_lock);
    3265                 :            : 
    3266                 :          0 :         mutex_lock(from->lock);
    3267                 :          0 :         list_for_each_entry(ref, &from->ctrl_refs, node) {
    3268                 :          0 :                 struct v4l2_ctrl *ctrl = ref->ctrl;
    3269                 :            :                 struct v4l2_ctrl_ref *new_ref;
    3270                 :            : 
    3271                 :            :                 /* Skip refs inherited from other devices */
    3272                 :          0 :                 if (ref->from_other_dev)
    3273                 :          0 :                         continue;
    3274                 :            :                 /* And buttons */
    3275                 :          0 :                 if (ctrl->type == V4L2_CTRL_TYPE_BUTTON)
    3276                 :          0 :                         continue;
    3277                 :          0 :                 err = handler_new_ref(hdl, ctrl, &new_ref, false, true);
    3278                 :          0 :                 if (err)
    3279                 :            :                         break;
    3280                 :            :         }
    3281                 :          0 :         mutex_unlock(from->lock);
    3282                 :          0 :         return err;
    3283                 :            : }
    3284                 :            : 
    3285                 :          0 : static void v4l2_ctrl_request_queue(struct media_request_object *obj)
    3286                 :            : {
    3287                 :            :         struct v4l2_ctrl_handler *hdl =
    3288                 :            :                 container_of(obj, struct v4l2_ctrl_handler, req_obj);
    3289                 :          0 :         struct v4l2_ctrl_handler *main_hdl = obj->priv;
    3290                 :            :         struct v4l2_ctrl_handler *prev_hdl = NULL;
    3291                 :            :         struct v4l2_ctrl_ref *ref_ctrl, *ref_ctrl_prev = NULL;
    3292                 :            : 
    3293                 :          0 :         mutex_lock(main_hdl->lock);
    3294                 :          0 :         if (list_empty(&main_hdl->requests_queued))
    3295                 :            :                 goto queue;
    3296                 :            : 
    3297                 :          0 :         prev_hdl = list_last_entry(&main_hdl->requests_queued,
    3298                 :            :                                    struct v4l2_ctrl_handler, requests_queued);
    3299                 :            :         /*
    3300                 :            :          * Note: prev_hdl and hdl must contain the same list of control
    3301                 :            :          * references, so if any differences are detected then that is a
    3302                 :            :          * driver bug and the WARN_ON is triggered.
    3303                 :            :          */
    3304                 :          0 :         mutex_lock(prev_hdl->lock);
    3305                 :          0 :         ref_ctrl_prev = list_first_entry(&prev_hdl->ctrl_refs,
    3306                 :            :                                          struct v4l2_ctrl_ref, node);
    3307                 :          0 :         list_for_each_entry(ref_ctrl, &hdl->ctrl_refs, node) {
    3308                 :          0 :                 if (ref_ctrl->req)
    3309                 :          0 :                         continue;
    3310                 :          0 :                 while (ref_ctrl_prev->ctrl->id < ref_ctrl->ctrl->id) {
    3311                 :            :                         /* Should never happen, but just in case... */
    3312                 :          0 :                         if (list_is_last(&ref_ctrl_prev->node,
    3313                 :          0 :                                          &prev_hdl->ctrl_refs))
    3314                 :            :                                 break;
    3315                 :            :                         ref_ctrl_prev = list_next_entry(ref_ctrl_prev, node);
    3316                 :            :                 }
    3317                 :          0 :                 if (WARN_ON(ref_ctrl_prev->ctrl->id != ref_ctrl->ctrl->id))
    3318                 :            :                         break;
    3319                 :          0 :                 ref_ctrl->req = ref_ctrl_prev->req;
    3320                 :            :         }
    3321                 :          0 :         mutex_unlock(prev_hdl->lock);
    3322                 :            : queue:
    3323                 :          0 :         list_add_tail(&hdl->requests_queued, &main_hdl->requests_queued);
    3324                 :          0 :         hdl->request_is_queued = true;
    3325                 :          0 :         mutex_unlock(main_hdl->lock);
    3326                 :          0 : }
    3327                 :            : 
    3328                 :          0 : static void v4l2_ctrl_request_unbind(struct media_request_object *obj)
    3329                 :            : {
    3330                 :            :         struct v4l2_ctrl_handler *hdl =
    3331                 :            :                 container_of(obj, struct v4l2_ctrl_handler, req_obj);
    3332                 :          0 :         struct v4l2_ctrl_handler *main_hdl = obj->priv;
    3333                 :            : 
    3334                 :          0 :         list_del_init(&hdl->requests);
    3335                 :          0 :         mutex_lock(main_hdl->lock);
    3336                 :          0 :         if (hdl->request_is_queued) {
    3337                 :          0 :                 list_del_init(&hdl->requests_queued);
    3338                 :          0 :                 hdl->request_is_queued = false;
    3339                 :            :         }
    3340                 :          0 :         mutex_unlock(main_hdl->lock);
    3341                 :          0 : }
    3342                 :            : 
    3343                 :          0 : static void v4l2_ctrl_request_release(struct media_request_object *obj)
    3344                 :            : {
    3345                 :            :         struct v4l2_ctrl_handler *hdl =
    3346                 :          0 :                 container_of(obj, struct v4l2_ctrl_handler, req_obj);
    3347                 :            : 
    3348                 :          0 :         v4l2_ctrl_handler_free(hdl);
    3349                 :          0 :         kfree(hdl);
    3350                 :          0 : }
    3351                 :            : 
    3352                 :            : static const struct media_request_object_ops req_ops = {
    3353                 :            :         .queue = v4l2_ctrl_request_queue,
    3354                 :            :         .unbind = v4l2_ctrl_request_unbind,
    3355                 :            :         .release = v4l2_ctrl_request_release,
    3356                 :            : };
    3357                 :            : 
    3358                 :          0 : struct v4l2_ctrl_handler *v4l2_ctrl_request_hdl_find(struct media_request *req,
    3359                 :            :                                         struct v4l2_ctrl_handler *parent)
    3360                 :            : {
    3361                 :            :         struct media_request_object *obj;
    3362                 :            : 
    3363                 :          0 :         if (WARN_ON(req->state != MEDIA_REQUEST_STATE_VALIDATING &&
    3364                 :            :                     req->state != MEDIA_REQUEST_STATE_QUEUED))
    3365                 :            :                 return NULL;
    3366                 :            : 
    3367                 :          0 :         obj = media_request_object_find(req, &req_ops, parent);
    3368                 :          0 :         if (obj)
    3369                 :          0 :                 return container_of(obj, struct v4l2_ctrl_handler, req_obj);
    3370                 :            :         return NULL;
    3371                 :            : }
    3372                 :            : EXPORT_SYMBOL_GPL(v4l2_ctrl_request_hdl_find);
    3373                 :            : 
    3374                 :            : struct v4l2_ctrl *
    3375                 :          0 : v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id)
    3376                 :            : {
    3377                 :          0 :         struct v4l2_ctrl_ref *ref = find_ref_lock(hdl, id);
    3378                 :            : 
    3379                 :          0 :         return (ref && ref->req == ref) ? ref->ctrl : NULL;
    3380                 :            : }
    3381                 :            : EXPORT_SYMBOL_GPL(v4l2_ctrl_request_hdl_ctrl_find);
    3382                 :            : 
    3383                 :          0 : static int v4l2_ctrl_request_bind(struct media_request *req,
    3384                 :            :                            struct v4l2_ctrl_handler *hdl,
    3385                 :            :                            struct v4l2_ctrl_handler *from)
    3386                 :            : {
    3387                 :            :         int ret;
    3388                 :            : 
    3389                 :          0 :         ret = v4l2_ctrl_request_clone(hdl, from);
    3390                 :            : 
    3391                 :          0 :         if (!ret) {
    3392                 :          0 :                 ret = media_request_object_bind(req, &req_ops,
    3393                 :            :                                                 from, false, &hdl->req_obj);
    3394                 :          0 :                 if (!ret)
    3395                 :          0 :                         list_add_tail(&hdl->requests, &from->requests);
    3396                 :            :         }
    3397                 :          0 :         return ret;
    3398                 :            : }
    3399                 :            : 
    3400                 :            : /* Some general notes on the atomic requirements of VIDIOC_G/TRY/S_EXT_CTRLS:
    3401                 :            : 
    3402                 :            :    It is not a fully atomic operation, just best-effort only. After all, if
    3403                 :            :    multiple controls have to be set through multiple i2c writes (for example)
    3404                 :            :    then some initial writes may succeed while others fail. Thus leaving the
    3405                 :            :    system in an inconsistent state. The question is how much effort you are
    3406                 :            :    willing to spend on trying to make something atomic that really isn't.
    3407                 :            : 
    3408                 :            :    From the point of view of an application the main requirement is that
    3409                 :            :    when you call VIDIOC_S_EXT_CTRLS and some values are invalid then an
    3410                 :            :    error should be returned without actually affecting any controls.
    3411                 :            : 
    3412                 :            :    If all the values are correct, then it is acceptable to just give up
    3413                 :            :    in case of low-level errors.
    3414                 :            : 
    3415                 :            :    It is important though that the application can tell when only a partial
    3416                 :            :    configuration was done. The way we do that is through the error_idx field
    3417                 :            :    of struct v4l2_ext_controls: if that is equal to the count field then no
    3418                 :            :    controls were affected. Otherwise all controls before that index were
    3419                 :            :    successful in performing their 'get' or 'set' operation, the control at
    3420                 :            :    the given index failed, and you don't know what happened with the controls
    3421                 :            :    after the failed one. Since if they were part of a control cluster they
    3422                 :            :    could have been successfully processed (if a cluster member was encountered
    3423                 :            :    at index < error_idx), they could have failed (if a cluster member was at
    3424                 :            :    error_idx), or they may not have been processed yet (if the first cluster
    3425                 :            :    member appeared after error_idx).
    3426                 :            : 
    3427                 :            :    It is all fairly theoretical, though. In practice all you can do is to
    3428                 :            :    bail out. If error_idx == count, then it is an application bug. If
    3429                 :            :    error_idx < count then it is only an application bug if the error code was
    3430                 :            :    EBUSY. That usually means that something started streaming just when you
    3431                 :            :    tried to set the controls. In all other cases it is a driver/hardware
    3432                 :            :    problem and all you can do is to retry or bail out.
    3433                 :            : 
    3434                 :            :    Note that these rules do not apply to VIDIOC_TRY_EXT_CTRLS: since that
    3435                 :            :    never modifies controls the error_idx is just set to whatever control
    3436                 :            :    has an invalid value.
    3437                 :            :  */
    3438                 :            : 
    3439                 :            : /* Prepare for the extended g/s/try functions.
    3440                 :            :    Find the controls in the control array and do some basic checks. */
    3441                 :          0 : static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
    3442                 :            :                              struct v4l2_ext_controls *cs,
    3443                 :            :                              struct v4l2_ctrl_helper *helpers,
    3444                 :            :                              struct video_device *vdev,
    3445                 :            :                              bool get)
    3446                 :            : {
    3447                 :            :         struct v4l2_ctrl_helper *h;
    3448                 :            :         bool have_clusters = false;
    3449                 :            :         u32 i;
    3450                 :            : 
    3451                 :          0 :         for (i = 0, h = helpers; i < cs->count; i++, h++) {
    3452                 :          0 :                 struct v4l2_ext_control *c = &cs->controls[i];
    3453                 :            :                 struct v4l2_ctrl_ref *ref;
    3454                 :            :                 struct v4l2_ctrl *ctrl;
    3455                 :          0 :                 u32 id = c->id & V4L2_CTRL_ID_MASK;
    3456                 :            : 
    3457                 :          0 :                 cs->error_idx = i;
    3458                 :            : 
    3459                 :          0 :                 if (cs->which &&
    3460                 :          0 :                     cs->which != V4L2_CTRL_WHICH_DEF_VAL &&
    3461                 :          0 :                     cs->which != V4L2_CTRL_WHICH_REQUEST_VAL &&
    3462                 :          0 :                     V4L2_CTRL_ID2WHICH(id) != cs->which) {
    3463                 :          0 :                         dprintk(vdev,
    3464                 :            :                                 "invalid which 0x%x or control id 0x%x\n",
    3465                 :            :                                 cs->which, id);
    3466                 :            :                         return -EINVAL;
    3467                 :            :                 }
    3468                 :            : 
    3469                 :            :                 /* Old-style private controls are not allowed for
    3470                 :            :                    extended controls */
    3471                 :          0 :                 if (id >= V4L2_CID_PRIVATE_BASE) {
    3472                 :          0 :                         dprintk(vdev,
    3473                 :            :                                 "old-style private controls not allowed\n");
    3474                 :            :                         return -EINVAL;
    3475                 :            :                 }
    3476                 :          0 :                 ref = find_ref_lock(hdl, id);
    3477                 :          0 :                 if (ref == NULL) {
    3478                 :          0 :                         dprintk(vdev, "cannot find control id 0x%x\n", id);
    3479                 :            :                         return -EINVAL;
    3480                 :            :                 }
    3481                 :          0 :                 h->ref = ref;
    3482                 :          0 :                 ctrl = ref->ctrl;
    3483                 :          0 :                 if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED) {
    3484                 :          0 :                         dprintk(vdev, "control id 0x%x is disabled\n", id);
    3485                 :            :                         return -EINVAL;
    3486                 :            :                 }
    3487                 :            : 
    3488                 :          0 :                 if (ctrl->cluster[0]->ncontrols > 1)
    3489                 :            :                         have_clusters = true;
    3490                 :          0 :                 if (ctrl->cluster[0] != ctrl)
    3491                 :          0 :                         ref = find_ref_lock(hdl, ctrl->cluster[0]->id);
    3492                 :          0 :                 if (ctrl->is_ptr && !ctrl->is_string) {
    3493                 :          0 :                         unsigned tot_size = ctrl->elems * ctrl->elem_size;
    3494                 :            : 
    3495                 :          0 :                         if (c->size < tot_size) {
    3496                 :            :                                 /*
    3497                 :            :                                  * In the get case the application first
    3498                 :            :                                  * queries to obtain the size of the control.
    3499                 :            :                                  */
    3500                 :          0 :                                 if (get) {
    3501                 :          0 :                                         c->size = tot_size;
    3502                 :          0 :                                         return -ENOSPC;
    3503                 :            :                                 }
    3504                 :          0 :                                 dprintk(vdev,
    3505                 :            :                                         "pointer control id 0x%x size too small, %d bytes but %d bytes needed\n",
    3506                 :            :                                         id, c->size, tot_size);
    3507                 :            :                                 return -EFAULT;
    3508                 :            :                         }
    3509                 :          0 :                         c->size = tot_size;
    3510                 :            :                 }
    3511                 :            :                 /* Store the ref to the master control of the cluster */
    3512                 :          0 :                 h->mref = ref;
    3513                 :            :                 /* Initially set next to 0, meaning that there is no other
    3514                 :            :                    control in this helper array belonging to the same
    3515                 :            :                    cluster */
    3516                 :          0 :                 h->next = 0;
    3517                 :            :         }
    3518                 :            : 
    3519                 :            :         /* We are done if there were no controls that belong to a multi-
    3520                 :            :            control cluster. */
    3521                 :          0 :         if (!have_clusters)
    3522                 :            :                 return 0;
    3523                 :            : 
    3524                 :            :         /* The code below figures out in O(n) time which controls in the list
    3525                 :            :            belong to the same cluster. */
    3526                 :            : 
    3527                 :            :         /* This has to be done with the handler lock taken. */
    3528                 :          0 :         mutex_lock(hdl->lock);
    3529                 :            : 
    3530                 :            :         /* First zero the helper field in the master control references */
    3531                 :          0 :         for (i = 0; i < cs->count; i++)
    3532                 :          0 :                 helpers[i].mref->helper = NULL;
    3533                 :          0 :         for (i = 0, h = helpers; i < cs->count; i++, h++) {
    3534                 :          0 :                 struct v4l2_ctrl_ref *mref = h->mref;
    3535                 :            : 
    3536                 :            :                 /* If the mref->helper is set, then it points to an earlier
    3537                 :            :                    helper that belongs to the same cluster. */
    3538                 :          0 :                 if (mref->helper) {
    3539                 :            :                         /* Set the next field of mref->helper to the current
    3540                 :            :                            index: this means that that earlier helper now
    3541                 :            :                            points to the next helper in the same cluster. */
    3542                 :          0 :                         mref->helper->next = i;
    3543                 :            :                         /* mref should be set only for the first helper in the
    3544                 :            :                            cluster, clear the others. */
    3545                 :          0 :                         h->mref = NULL;
    3546                 :            :                 }
    3547                 :            :                 /* Point the mref helper to the current helper struct. */
    3548                 :          0 :                 mref->helper = h;
    3549                 :            :         }
    3550                 :          0 :         mutex_unlock(hdl->lock);
    3551                 :          0 :         return 0;
    3552                 :            : }
    3553                 :            : 
    3554                 :            : /* Handles the corner case where cs->count == 0. It checks whether the
    3555                 :            :    specified control class exists. If that class ID is 0, then it checks
    3556                 :            :    whether there are any controls at all. */
    3557                 :          0 : static int class_check(struct v4l2_ctrl_handler *hdl, u32 which)
    3558                 :            : {
    3559                 :          0 :         if (which == 0 || which == V4L2_CTRL_WHICH_DEF_VAL ||
    3560                 :            :             which == V4L2_CTRL_WHICH_REQUEST_VAL)
    3561                 :            :                 return 0;
    3562                 :          0 :         return find_ref_lock(hdl, which | 1) ? 0 : -EINVAL;
    3563                 :            : }
    3564                 :            : 
    3565                 :            : /* Get extended controls. Allocates the helpers array if needed. */
    3566                 :          0 : static int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *hdl,
    3567                 :            :                                    struct v4l2_ext_controls *cs,
    3568                 :            :                                    struct video_device *vdev)
    3569                 :            : {
    3570                 :            :         struct v4l2_ctrl_helper helper[4];
    3571                 :            :         struct v4l2_ctrl_helper *helpers = helper;
    3572                 :            :         int ret;
    3573                 :            :         int i, j;
    3574                 :            :         bool def_value;
    3575                 :            : 
    3576                 :          0 :         def_value = (cs->which == V4L2_CTRL_WHICH_DEF_VAL);
    3577                 :            : 
    3578                 :          0 :         cs->error_idx = cs->count;
    3579                 :          0 :         cs->which = V4L2_CTRL_ID2WHICH(cs->which);
    3580                 :            : 
    3581                 :          0 :         if (hdl == NULL)
    3582                 :            :                 return -EINVAL;
    3583                 :            : 
    3584                 :          0 :         if (cs->count == 0)
    3585                 :          0 :                 return class_check(hdl, cs->which);
    3586                 :            : 
    3587                 :          0 :         if (cs->count > ARRAY_SIZE(helper)) {
    3588                 :          0 :                 helpers = kvmalloc_array(cs->count, sizeof(helper[0]),
    3589                 :            :                                          GFP_KERNEL);
    3590                 :          0 :                 if (helpers == NULL)
    3591                 :            :                         return -ENOMEM;
    3592                 :            :         }
    3593                 :            : 
    3594                 :          0 :         ret = prepare_ext_ctrls(hdl, cs, helpers, vdev, true);
    3595                 :          0 :         cs->error_idx = cs->count;
    3596                 :            : 
    3597                 :          0 :         for (i = 0; !ret && i < cs->count; i++)
    3598                 :          0 :                 if (helpers[i].ref->ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
    3599                 :            :                         ret = -EACCES;
    3600                 :            : 
    3601                 :          0 :         for (i = 0; !ret && i < cs->count; i++) {
    3602                 :            :                 int (*ctrl_to_user)(struct v4l2_ext_control *c,
    3603                 :            :                                     struct v4l2_ctrl *ctrl);
    3604                 :            :                 struct v4l2_ctrl *master;
    3605                 :            : 
    3606                 :          0 :                 ctrl_to_user = def_value ? def_to_user : cur_to_user;
    3607                 :            : 
    3608                 :          0 :                 if (helpers[i].mref == NULL)
    3609                 :          0 :                         continue;
    3610                 :            : 
    3611                 :          0 :                 master = helpers[i].mref->ctrl;
    3612                 :          0 :                 cs->error_idx = i;
    3613                 :            : 
    3614                 :            :                 v4l2_ctrl_lock(master);
    3615                 :            : 
    3616                 :            :                 /* g_volatile_ctrl will update the new control values */
    3617                 :          0 :                 if (!def_value &&
    3618                 :          0 :                     ((master->flags & V4L2_CTRL_FLAG_VOLATILE) ||
    3619                 :          0 :                     (master->has_volatiles && !is_cur_manual(master)))) {
    3620                 :          0 :                         for (j = 0; j < master->ncontrols; j++)
    3621                 :          0 :                                 cur_to_new(master->cluster[j]);
    3622                 :          0 :                         ret = call_op(master, g_volatile_ctrl);
    3623                 :            :                         ctrl_to_user = new_to_user;
    3624                 :            :                 }
    3625                 :            :                 /* If OK, then copy the current (for non-volatile controls)
    3626                 :            :                    or the new (for volatile controls) control values to the
    3627                 :            :                    caller */
    3628                 :          0 :                 if (!ret) {
    3629                 :            :                         u32 idx = i;
    3630                 :            : 
    3631                 :            :                         do {
    3632                 :          0 :                                 if (helpers[idx].ref->req)
    3633                 :          0 :                                         ret = req_to_user(cs->controls + idx,
    3634                 :            :                                                 helpers[idx].ref->req);
    3635                 :            :                                 else
    3636                 :          0 :                                         ret = ctrl_to_user(cs->controls + idx,
    3637                 :            :                                                 helpers[idx].ref->ctrl);
    3638                 :          0 :                                 idx = helpers[idx].next;
    3639                 :          0 :                         } while (!ret && idx);
    3640                 :            :                 }
    3641                 :            :                 v4l2_ctrl_unlock(master);
    3642                 :            :         }
    3643                 :            : 
    3644                 :          0 :         if (cs->count > ARRAY_SIZE(helper))
    3645                 :          0 :                 kvfree(helpers);
    3646                 :          0 :         return ret;
    3647                 :            : }
    3648                 :            : 
    3649                 :            : static struct media_request_object *
    3650                 :          0 : v4l2_ctrls_find_req_obj(struct v4l2_ctrl_handler *hdl,
    3651                 :            :                         struct media_request *req, bool set)
    3652                 :            : {
    3653                 :            :         struct media_request_object *obj;
    3654                 :            :         struct v4l2_ctrl_handler *new_hdl;
    3655                 :            :         int ret;
    3656                 :            : 
    3657                 :          0 :         if (IS_ERR(req))
    3658                 :            :                 return ERR_CAST(req);
    3659                 :            : 
    3660                 :          0 :         if (set && WARN_ON(req->state != MEDIA_REQUEST_STATE_UPDATING))
    3661                 :            :                 return ERR_PTR(-EBUSY);
    3662                 :            : 
    3663                 :          0 :         obj = media_request_object_find(req, &req_ops, hdl);
    3664                 :          0 :         if (obj)
    3665                 :            :                 return obj;
    3666                 :          0 :         if (!set)
    3667                 :            :                 return ERR_PTR(-ENOENT);
    3668                 :            : 
    3669                 :          0 :         new_hdl = kzalloc(sizeof(*new_hdl), GFP_KERNEL);
    3670                 :          0 :         if (!new_hdl)
    3671                 :            :                 return ERR_PTR(-ENOMEM);
    3672                 :            : 
    3673                 :          0 :         obj = &new_hdl->req_obj;
    3674                 :          0 :         ret = v4l2_ctrl_handler_init(new_hdl, (hdl->nr_of_buckets - 1) * 8);
    3675                 :          0 :         if (!ret)
    3676                 :          0 :                 ret = v4l2_ctrl_request_bind(req, new_hdl, hdl);
    3677                 :          0 :         if (ret) {
    3678                 :          0 :                 kfree(new_hdl);
    3679                 :            : 
    3680                 :          0 :                 return ERR_PTR(ret);
    3681                 :            :         }
    3682                 :            : 
    3683                 :            :         media_request_object_get(obj);
    3684                 :          0 :         return obj;
    3685                 :            : }
    3686                 :            : 
    3687                 :          0 : int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
    3688                 :            :                      struct media_device *mdev, struct v4l2_ext_controls *cs)
    3689                 :            : {
    3690                 :            :         struct media_request_object *obj = NULL;
    3691                 :            :         struct media_request *req = NULL;
    3692                 :            :         int ret;
    3693                 :            : 
    3694                 :          0 :         if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) {
    3695                 :          0 :                 if (!mdev || cs->request_fd < 0)
    3696                 :            :                         return -EINVAL;
    3697                 :            : 
    3698                 :          0 :                 req = media_request_get_by_fd(mdev, cs->request_fd);
    3699                 :          0 :                 if (IS_ERR(req))
    3700                 :          0 :                         return PTR_ERR(req);
    3701                 :            : 
    3702                 :          0 :                 if (req->state != MEDIA_REQUEST_STATE_COMPLETE) {
    3703                 :          0 :                         media_request_put(req);
    3704                 :          0 :                         return -EACCES;
    3705                 :            :                 }
    3706                 :            : 
    3707                 :          0 :                 ret = media_request_lock_for_access(req);
    3708                 :          0 :                 if (ret) {
    3709                 :          0 :                         media_request_put(req);
    3710                 :          0 :                         return ret;
    3711                 :            :                 }
    3712                 :            : 
    3713                 :          0 :                 obj = v4l2_ctrls_find_req_obj(hdl, req, false);
    3714                 :          0 :                 if (IS_ERR(obj)) {
    3715                 :          0 :                         media_request_unlock_for_access(req);
    3716                 :          0 :                         media_request_put(req);
    3717                 :          0 :                         return PTR_ERR(obj);
    3718                 :            :                 }
    3719                 :            : 
    3720                 :          0 :                 hdl = container_of(obj, struct v4l2_ctrl_handler,
    3721                 :            :                                    req_obj);
    3722                 :            :         }
    3723                 :            : 
    3724                 :          0 :         ret = v4l2_g_ext_ctrls_common(hdl, cs, vdev);
    3725                 :            : 
    3726                 :          0 :         if (obj) {
    3727                 :          0 :                 media_request_unlock_for_access(req);
    3728                 :          0 :                 media_request_object_put(obj);
    3729                 :          0 :                 media_request_put(req);
    3730                 :            :         }
    3731                 :          0 :         return ret;
    3732                 :            : }
    3733                 :            : EXPORT_SYMBOL(v4l2_g_ext_ctrls);
    3734                 :            : 
    3735                 :            : /* Helper function to get a single control */
    3736                 :          0 : static int get_ctrl(struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c)
    3737                 :            : {
    3738                 :          0 :         struct v4l2_ctrl *master = ctrl->cluster[0];
    3739                 :            :         int ret = 0;
    3740                 :            :         int i;
    3741                 :            : 
    3742                 :            :         /* Compound controls are not supported. The new_to_user() and
    3743                 :            :          * cur_to_user() calls below would need to be modified not to access
    3744                 :            :          * userspace memory when called from get_ctrl().
    3745                 :            :          */
    3746                 :          0 :         if (!ctrl->is_int && ctrl->type != V4L2_CTRL_TYPE_INTEGER64)
    3747                 :            :                 return -EINVAL;
    3748                 :            : 
    3749                 :          0 :         if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
    3750                 :            :                 return -EACCES;
    3751                 :            : 
    3752                 :            :         v4l2_ctrl_lock(master);
    3753                 :            :         /* g_volatile_ctrl will update the current control values */
    3754                 :          0 :         if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) {
    3755                 :          0 :                 for (i = 0; i < master->ncontrols; i++)
    3756                 :          0 :                         cur_to_new(master->cluster[i]);
    3757                 :          0 :                 ret = call_op(master, g_volatile_ctrl);
    3758                 :            :                 new_to_user(c, ctrl);
    3759                 :            :         } else {
    3760                 :            :                 cur_to_user(c, ctrl);
    3761                 :            :         }
    3762                 :            :         v4l2_ctrl_unlock(master);
    3763                 :          0 :         return ret;
    3764                 :            : }
    3765                 :            : 
    3766                 :          0 : int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control)
    3767                 :            : {
    3768                 :          0 :         struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id);
    3769                 :            :         struct v4l2_ext_control c;
    3770                 :            :         int ret;
    3771                 :            : 
    3772                 :          0 :         if (ctrl == NULL || !ctrl->is_int)
    3773                 :            :                 return -EINVAL;
    3774                 :          0 :         ret = get_ctrl(ctrl, &c);
    3775                 :          0 :         control->value = c.value;
    3776                 :          0 :         return ret;
    3777                 :            : }
    3778                 :            : EXPORT_SYMBOL(v4l2_g_ctrl);
    3779                 :            : 
    3780                 :          0 : s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl)
    3781                 :            : {
    3782                 :            :         struct v4l2_ext_control c;
    3783                 :            : 
    3784                 :            :         /* It's a driver bug if this happens. */
    3785                 :          0 :         WARN_ON(!ctrl->is_int);
    3786                 :          0 :         c.value = 0;
    3787                 :          0 :         get_ctrl(ctrl, &c);
    3788                 :          0 :         return c.value;
    3789                 :            : }
    3790                 :            : EXPORT_SYMBOL(v4l2_ctrl_g_ctrl);
    3791                 :            : 
    3792                 :          0 : s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl)
    3793                 :            : {
    3794                 :            :         struct v4l2_ext_control c;
    3795                 :            : 
    3796                 :            :         /* It's a driver bug if this happens. */
    3797                 :          0 :         WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64);
    3798                 :          0 :         c.value64 = 0;
    3799                 :          0 :         get_ctrl(ctrl, &c);
    3800                 :          0 :         return c.value64;
    3801                 :            : }
    3802                 :            : EXPORT_SYMBOL(v4l2_ctrl_g_ctrl_int64);
    3803                 :            : 
    3804                 :            : 
    3805                 :            : /* Core function that calls try/s_ctrl and ensures that the new value is
    3806                 :            :    copied to the current value on a set.
    3807                 :            :    Must be called with ctrl->handler->lock held. */
    3808                 :          0 : static int try_or_set_cluster(struct v4l2_fh *fh, struct v4l2_ctrl *master,
    3809                 :            :                               bool set, u32 ch_flags)
    3810                 :            : {
    3811                 :            :         bool update_flag;
    3812                 :            :         int ret;
    3813                 :            :         int i;
    3814                 :            : 
    3815                 :            :         /* Go through the cluster and either validate the new value or
    3816                 :            :            (if no new value was set), copy the current value to the new
    3817                 :            :            value, ensuring a consistent view for the control ops when
    3818                 :            :            called. */
    3819                 :          0 :         for (i = 0; i < master->ncontrols; i++) {
    3820                 :          0 :                 struct v4l2_ctrl *ctrl = master->cluster[i];
    3821                 :            : 
    3822                 :          0 :                 if (ctrl == NULL)
    3823                 :          0 :                         continue;
    3824                 :            : 
    3825                 :          0 :                 if (!ctrl->is_new) {
    3826                 :          0 :                         cur_to_new(ctrl);
    3827                 :          0 :                         continue;
    3828                 :            :                 }
    3829                 :            :                 /* Check again: it may have changed since the
    3830                 :            :                    previous check in try_or_set_ext_ctrls(). */
    3831                 :          0 :                 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED))
    3832                 :            :                         return -EBUSY;
    3833                 :            :         }
    3834                 :            : 
    3835                 :          0 :         ret = call_op(master, try_ctrl);
    3836                 :            : 
    3837                 :            :         /* Don't set if there is no change */
    3838                 :          0 :         if (ret || !set || !cluster_changed(master))
    3839                 :          0 :                 return ret;
    3840                 :          0 :         ret = call_op(master, s_ctrl);
    3841                 :          0 :         if (ret)
    3842                 :            :                 return ret;
    3843                 :            : 
    3844                 :            :         /* If OK, then make the new values permanent. */
    3845                 :          0 :         update_flag = is_cur_manual(master) != is_new_manual(master);
    3846                 :            : 
    3847                 :          0 :         for (i = 0; i < master->ncontrols; i++) {
    3848                 :            :                 /*
    3849                 :            :                  * If we switch from auto to manual mode, and this cluster
    3850                 :            :                  * contains volatile controls, then all non-master controls
    3851                 :            :                  * have to be marked as changed. The 'new' value contains
    3852                 :            :                  * the volatile value (obtained by update_from_auto_cluster),
    3853                 :            :                  * which now has to become the current value.
    3854                 :            :                  */
    3855                 :          0 :                 if (i && update_flag && is_new_manual(master) &&
    3856                 :          0 :                     master->has_volatiles && master->cluster[i])
    3857                 :          0 :                         master->cluster[i]->has_changed = true;
    3858                 :            : 
    3859                 :          0 :                 new_to_cur(fh, master->cluster[i], ch_flags |
    3860                 :          0 :                         ((update_flag && i > 0) ? V4L2_EVENT_CTRL_CH_FLAGS : 0));
    3861                 :            :         }
    3862                 :            :         return 0;
    3863                 :            : }
    3864                 :            : 
    3865                 :            : /* Validate controls. */
    3866                 :          0 : static int validate_ctrls(struct v4l2_ext_controls *cs,
    3867                 :            :                           struct v4l2_ctrl_helper *helpers,
    3868                 :            :                           struct video_device *vdev,
    3869                 :            :                           bool set)
    3870                 :            : {
    3871                 :            :         unsigned i;
    3872                 :            :         int ret = 0;
    3873                 :            : 
    3874                 :          0 :         cs->error_idx = cs->count;
    3875                 :          0 :         for (i = 0; i < cs->count; i++) {
    3876                 :          0 :                 struct v4l2_ctrl *ctrl = helpers[i].ref->ctrl;
    3877                 :            :                 union v4l2_ctrl_ptr p_new;
    3878                 :            : 
    3879                 :          0 :                 cs->error_idx = i;
    3880                 :            : 
    3881                 :          0 :                 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) {
    3882                 :          0 :                         dprintk(vdev,
    3883                 :            :                                 "control id 0x%x is read-only\n",
    3884                 :            :                                 ctrl->id);
    3885                 :            :                         return -EACCES;
    3886                 :            :                 }
    3887                 :            :                 /* This test is also done in try_set_control_cluster() which
    3888                 :            :                    is called in atomic context, so that has the final say,
    3889                 :            :                    but it makes sense to do an up-front check as well. Once
    3890                 :            :                    an error occurs in try_set_control_cluster() some other
    3891                 :            :                    controls may have been set already and we want to do a
    3892                 :            :                    best-effort to avoid that. */
    3893                 :          0 :                 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) {
    3894                 :          0 :                         dprintk(vdev,
    3895                 :            :                                 "control id 0x%x is grabbed, cannot set\n",
    3896                 :            :                                 ctrl->id);
    3897                 :            :                         return -EBUSY;
    3898                 :            :                 }
    3899                 :            :                 /*
    3900                 :            :                  * Skip validation for now if the payload needs to be copied
    3901                 :            :                  * from userspace into kernelspace. We'll validate those later.
    3902                 :            :                  */
    3903                 :          0 :                 if (ctrl->is_ptr)
    3904                 :          0 :                         continue;
    3905                 :          0 :                 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
    3906                 :          0 :                         p_new.p_s64 = &cs->controls[i].value64;
    3907                 :            :                 else
    3908                 :          0 :                         p_new.p_s32 = &cs->controls[i].value;
    3909                 :            :                 ret = validate_new(ctrl, p_new);
    3910                 :          0 :                 if (ret)
    3911                 :          0 :                         return ret;
    3912                 :            :         }
    3913                 :            :         return 0;
    3914                 :            : }
    3915                 :            : 
    3916                 :            : /* Obtain the current volatile values of an autocluster and mark them
    3917                 :            :    as new. */
    3918                 :          0 : static void update_from_auto_cluster(struct v4l2_ctrl *master)
    3919                 :            : {
    3920                 :            :         int i;
    3921                 :            : 
    3922                 :          0 :         for (i = 1; i < master->ncontrols; i++)
    3923                 :          0 :                 cur_to_new(master->cluster[i]);
    3924                 :          0 :         if (!call_op(master, g_volatile_ctrl))
    3925                 :          0 :                 for (i = 1; i < master->ncontrols; i++)
    3926                 :          0 :                         if (master->cluster[i])
    3927                 :          0 :                                 master->cluster[i]->is_new = 1;
    3928                 :          0 : }
    3929                 :            : 
    3930                 :            : /* Try or try-and-set controls */
    3931                 :          0 : static int try_set_ext_ctrls_common(struct v4l2_fh *fh,
    3932                 :            :                                     struct v4l2_ctrl_handler *hdl,
    3933                 :            :                                     struct v4l2_ext_controls *cs,
    3934                 :            :                                     struct video_device *vdev, bool set)
    3935                 :            : {
    3936                 :            :         struct v4l2_ctrl_helper helper[4];
    3937                 :            :         struct v4l2_ctrl_helper *helpers = helper;
    3938                 :            :         unsigned i, j;
    3939                 :            :         int ret;
    3940                 :            : 
    3941                 :          0 :         cs->error_idx = cs->count;
    3942                 :            : 
    3943                 :            :         /* Default value cannot be changed */
    3944                 :          0 :         if (cs->which == V4L2_CTRL_WHICH_DEF_VAL) {
    3945                 :          0 :                 dprintk(vdev, "%s: cannot change default value\n",
    3946                 :            :                         video_device_node_name(vdev));
    3947                 :            :                 return -EINVAL;
    3948                 :            :         }
    3949                 :            : 
    3950                 :          0 :         cs->which = V4L2_CTRL_ID2WHICH(cs->which);
    3951                 :            : 
    3952                 :          0 :         if (hdl == NULL) {
    3953                 :          0 :                 dprintk(vdev, "%s: invalid null control handler\n",
    3954                 :            :                         video_device_node_name(vdev));
    3955                 :            :                 return -EINVAL;
    3956                 :            :         }
    3957                 :            : 
    3958                 :          0 :         if (cs->count == 0)
    3959                 :          0 :                 return class_check(hdl, cs->which);
    3960                 :            : 
    3961                 :          0 :         if (cs->count > ARRAY_SIZE(helper)) {
    3962                 :          0 :                 helpers = kvmalloc_array(cs->count, sizeof(helper[0]),
    3963                 :            :                                          GFP_KERNEL);
    3964                 :          0 :                 if (!helpers)
    3965                 :            :                         return -ENOMEM;
    3966                 :            :         }
    3967                 :          0 :         ret = prepare_ext_ctrls(hdl, cs, helpers, vdev, false);
    3968                 :          0 :         if (!ret)
    3969                 :          0 :                 ret = validate_ctrls(cs, helpers, vdev, set);
    3970                 :          0 :         if (ret && set)
    3971                 :          0 :                 cs->error_idx = cs->count;
    3972                 :          0 :         for (i = 0; !ret && i < cs->count; i++) {
    3973                 :            :                 struct v4l2_ctrl *master;
    3974                 :            :                 u32 idx = i;
    3975                 :            : 
    3976                 :          0 :                 if (helpers[i].mref == NULL)
    3977                 :          0 :                         continue;
    3978                 :            : 
    3979                 :          0 :                 cs->error_idx = i;
    3980                 :          0 :                 master = helpers[i].mref->ctrl;
    3981                 :            :                 v4l2_ctrl_lock(master);
    3982                 :            : 
    3983                 :            :                 /* Reset the 'is_new' flags of the cluster */
    3984                 :          0 :                 for (j = 0; j < master->ncontrols; j++)
    3985                 :          0 :                         if (master->cluster[j])
    3986                 :          0 :                                 master->cluster[j]->is_new = 0;
    3987                 :            : 
    3988                 :            :                 /* For volatile autoclusters that are currently in auto mode
    3989                 :            :                    we need to discover if it will be set to manual mode.
    3990                 :            :                    If so, then we have to copy the current volatile values
    3991                 :            :                    first since those will become the new manual values (which
    3992                 :            :                    may be overwritten by explicit new values from this set
    3993                 :            :                    of controls). */
    3994                 :          0 :                 if (master->is_auto && master->has_volatiles &&
    3995                 :            :                                                 !is_cur_manual(master)) {
    3996                 :            :                         /* Pick an initial non-manual value */
    3997                 :          0 :                         s32 new_auto_val = master->manual_mode_value + 1;
    3998                 :            :                         u32 tmp_idx = idx;
    3999                 :            : 
    4000                 :            :                         do {
    4001                 :            :                                 /* Check if the auto control is part of the
    4002                 :            :                                    list, and remember the new value. */
    4003                 :          0 :                                 if (helpers[tmp_idx].ref->ctrl == master)
    4004                 :          0 :                                         new_auto_val = cs->controls[tmp_idx].value;
    4005                 :          0 :                                 tmp_idx = helpers[tmp_idx].next;
    4006                 :          0 :                         } while (tmp_idx);
    4007                 :            :                         /* If the new value == the manual value, then copy
    4008                 :            :                            the current volatile values. */
    4009                 :          0 :                         if (new_auto_val == master->manual_mode_value)
    4010                 :          0 :                                 update_from_auto_cluster(master);
    4011                 :            :                 }
    4012                 :            : 
    4013                 :            :                 /* Copy the new caller-supplied control values.
    4014                 :            :                    user_to_new() sets 'is_new' to 1. */
    4015                 :            :                 do {
    4016                 :          0 :                         struct v4l2_ctrl *ctrl = helpers[idx].ref->ctrl;
    4017                 :            : 
    4018                 :          0 :                         ret = user_to_new(cs->controls + idx, ctrl);
    4019                 :          0 :                         if (!ret && ctrl->is_ptr)
    4020                 :            :                                 ret = validate_new(ctrl, ctrl->p_new);
    4021                 :          0 :                         idx = helpers[idx].next;
    4022                 :          0 :                 } while (!ret && idx);
    4023                 :            : 
    4024                 :          0 :                 if (!ret)
    4025                 :          0 :                         ret = try_or_set_cluster(fh, master,
    4026                 :          0 :                                                  !hdl->req_obj.req && set, 0);
    4027                 :          0 :                 if (!ret && hdl->req_obj.req && set) {
    4028                 :          0 :                         for (j = 0; j < master->ncontrols; j++) {
    4029                 :          0 :                                 struct v4l2_ctrl_ref *ref =
    4030                 :          0 :                                         find_ref(hdl, master->cluster[j]->id);
    4031                 :            : 
    4032                 :          0 :                                 new_to_req(ref);
    4033                 :            :                         }
    4034                 :            :                 }
    4035                 :            : 
    4036                 :            :                 /* Copy the new values back to userspace. */
    4037                 :          0 :                 if (!ret) {
    4038                 :            :                         idx = i;
    4039                 :            :                         do {
    4040                 :          0 :                                 ret = new_to_user(cs->controls + idx,
    4041                 :          0 :                                                 helpers[idx].ref->ctrl);
    4042                 :          0 :                                 idx = helpers[idx].next;
    4043                 :          0 :                         } while (!ret && idx);
    4044                 :            :                 }
    4045                 :            :                 v4l2_ctrl_unlock(master);
    4046                 :            :         }
    4047                 :            : 
    4048                 :          0 :         if (cs->count > ARRAY_SIZE(helper))
    4049                 :          0 :                 kvfree(helpers);
    4050                 :          0 :         return ret;
    4051                 :            : }
    4052                 :            : 
    4053                 :          0 : static int try_set_ext_ctrls(struct v4l2_fh *fh,
    4054                 :            :                              struct v4l2_ctrl_handler *hdl,
    4055                 :            :                              struct video_device *vdev,
    4056                 :            :                              struct media_device *mdev,
    4057                 :            :                              struct v4l2_ext_controls *cs, bool set)
    4058                 :            : {
    4059                 :            :         struct media_request_object *obj = NULL;
    4060                 :            :         struct media_request *req = NULL;
    4061                 :            :         int ret;
    4062                 :            : 
    4063                 :          0 :         if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) {
    4064                 :          0 :                 if (!mdev) {
    4065                 :          0 :                         dprintk(vdev, "%s: missing media device\n",
    4066                 :            :                                 video_device_node_name(vdev));
    4067                 :            :                         return -EINVAL;
    4068                 :            :                 }
    4069                 :            : 
    4070                 :          0 :                 if (cs->request_fd < 0) {
    4071                 :          0 :                         dprintk(vdev, "%s: invalid request fd %d\n",
    4072                 :            :                                 video_device_node_name(vdev), cs->request_fd);
    4073                 :            :                         return -EINVAL;
    4074                 :            :                 }
    4075                 :            : 
    4076                 :          0 :                 req = media_request_get_by_fd(mdev, cs->request_fd);
    4077                 :          0 :                 if (IS_ERR(req)) {
    4078                 :          0 :                         dprintk(vdev, "%s: cannot find request fd %d\n",
    4079                 :            :                                 video_device_node_name(vdev), cs->request_fd);
    4080                 :          0 :                         return PTR_ERR(req);
    4081                 :            :                 }
    4082                 :            : 
    4083                 :          0 :                 ret = media_request_lock_for_update(req);
    4084                 :          0 :                 if (ret) {
    4085                 :          0 :                         dprintk(vdev, "%s: cannot lock request fd %d\n",
    4086                 :            :                                 video_device_node_name(vdev), cs->request_fd);
    4087                 :          0 :                         media_request_put(req);
    4088                 :          0 :                         return ret;
    4089                 :            :                 }
    4090                 :            : 
    4091                 :          0 :                 obj = v4l2_ctrls_find_req_obj(hdl, req, set);
    4092                 :          0 :                 if (IS_ERR(obj)) {
    4093                 :          0 :                         dprintk(vdev,
    4094                 :            :                                 "%s: cannot find request object for request fd %d\n",
    4095                 :            :                                 video_device_node_name(vdev),
    4096                 :            :                                 cs->request_fd);
    4097                 :          0 :                         media_request_unlock_for_update(req);
    4098                 :          0 :                         media_request_put(req);
    4099                 :          0 :                         return PTR_ERR(obj);
    4100                 :            :                 }
    4101                 :          0 :                 hdl = container_of(obj, struct v4l2_ctrl_handler,
    4102                 :            :                                    req_obj);
    4103                 :            :         }
    4104                 :            : 
    4105                 :          0 :         ret = try_set_ext_ctrls_common(fh, hdl, cs, vdev, set);
    4106                 :          0 :         if (ret)
    4107                 :          0 :                 dprintk(vdev,
    4108                 :            :                         "%s: try_set_ext_ctrls_common failed (%d)\n",
    4109                 :            :                         video_device_node_name(vdev), ret);
    4110                 :            : 
    4111                 :          0 :         if (obj) {
    4112                 :          0 :                 media_request_unlock_for_update(req);
    4113                 :          0 :                 media_request_object_put(obj);
    4114                 :          0 :                 media_request_put(req);
    4115                 :            :         }
    4116                 :            : 
    4117                 :          0 :         return ret;
    4118                 :            : }
    4119                 :            : 
    4120                 :          0 : int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
    4121                 :            :                        struct video_device *vdev,
    4122                 :            :                        struct media_device *mdev,
    4123                 :            :                        struct v4l2_ext_controls *cs)
    4124                 :            : {
    4125                 :          0 :         return try_set_ext_ctrls(NULL, hdl, vdev, mdev, cs, false);
    4126                 :            : }
    4127                 :            : EXPORT_SYMBOL(v4l2_try_ext_ctrls);
    4128                 :            : 
    4129                 :          0 : int v4l2_s_ext_ctrls(struct v4l2_fh *fh,
    4130                 :            :                      struct v4l2_ctrl_handler *hdl,
    4131                 :            :                      struct video_device *vdev,
    4132                 :            :                      struct media_device *mdev,
    4133                 :            :                      struct v4l2_ext_controls *cs)
    4134                 :            : {
    4135                 :          0 :         return try_set_ext_ctrls(fh, hdl, vdev, mdev, cs, true);
    4136                 :            : }
    4137                 :            : EXPORT_SYMBOL(v4l2_s_ext_ctrls);
    4138                 :            : 
    4139                 :            : /* Helper function for VIDIOC_S_CTRL compatibility */
    4140                 :          0 : static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags)
    4141                 :            : {
    4142                 :          0 :         struct v4l2_ctrl *master = ctrl->cluster[0];
    4143                 :            :         int ret;
    4144                 :            :         int i;
    4145                 :            : 
    4146                 :            :         /* Reset the 'is_new' flags of the cluster */
    4147                 :          0 :         for (i = 0; i < master->ncontrols; i++)
    4148                 :          0 :                 if (master->cluster[i])
    4149                 :          0 :                         master->cluster[i]->is_new = 0;
    4150                 :            : 
    4151                 :            :         ret = validate_new(ctrl, ctrl->p_new);
    4152                 :          0 :         if (ret)
    4153                 :            :                 return ret;
    4154                 :            : 
    4155                 :            :         /* For autoclusters with volatiles that are switched from auto to
    4156                 :            :            manual mode we have to update the current volatile values since
    4157                 :            :            those will become the initial manual values after such a switch. */
    4158                 :          0 :         if (master->is_auto && master->has_volatiles && ctrl == master &&
    4159                 :          0 :             !is_cur_manual(master) && ctrl->val == master->manual_mode_value)
    4160                 :          0 :                 update_from_auto_cluster(master);
    4161                 :            : 
    4162                 :          0 :         ctrl->is_new = 1;
    4163                 :          0 :         return try_or_set_cluster(fh, master, true, ch_flags);
    4164                 :            : }
    4165                 :            : 
    4166                 :            : /* Helper function for VIDIOC_S_CTRL compatibility */
    4167                 :          0 : static int set_ctrl_lock(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
    4168                 :            :                          struct v4l2_ext_control *c)
    4169                 :            : {
    4170                 :            :         int ret;
    4171                 :            : 
    4172                 :            :         v4l2_ctrl_lock(ctrl);
    4173                 :            :         user_to_new(c, ctrl);
    4174                 :          0 :         ret = set_ctrl(fh, ctrl, 0);
    4175                 :          0 :         if (!ret)
    4176                 :            :                 cur_to_user(c, ctrl);
    4177                 :            :         v4l2_ctrl_unlock(ctrl);
    4178                 :          0 :         return ret;
    4179                 :            : }
    4180                 :            : 
    4181                 :          0 : int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
    4182                 :            :                                         struct v4l2_control *control)
    4183                 :            : {
    4184                 :          0 :         struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id);
    4185                 :          0 :         struct v4l2_ext_control c = { control->id };
    4186                 :            :         int ret;
    4187                 :            : 
    4188                 :          0 :         if (ctrl == NULL || !ctrl->is_int)
    4189                 :            :                 return -EINVAL;
    4190                 :            : 
    4191                 :          0 :         if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
    4192                 :            :                 return -EACCES;
    4193                 :            : 
    4194                 :          0 :         c.value = control->value;
    4195                 :          0 :         ret = set_ctrl_lock(fh, ctrl, &c);
    4196                 :          0 :         control->value = c.value;
    4197                 :          0 :         return ret;
    4198                 :            : }
    4199                 :            : EXPORT_SYMBOL(v4l2_s_ctrl);
    4200                 :            : 
    4201                 :          0 : int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
    4202                 :            : {
    4203                 :            :         lockdep_assert_held(ctrl->handler->lock);
    4204                 :            : 
    4205                 :            :         /* It's a driver bug if this happens. */
    4206                 :          0 :         WARN_ON(!ctrl->is_int);
    4207                 :          0 :         ctrl->val = val;
    4208                 :          0 :         return set_ctrl(NULL, ctrl, 0);
    4209                 :            : }
    4210                 :            : EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl);
    4211                 :            : 
    4212                 :          0 : int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
    4213                 :            : {
    4214                 :            :         lockdep_assert_held(ctrl->handler->lock);
    4215                 :            : 
    4216                 :            :         /* It's a driver bug if this happens. */
    4217                 :          0 :         WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64);
    4218                 :          0 :         *ctrl->p_new.p_s64 = val;
    4219                 :          0 :         return set_ctrl(NULL, ctrl, 0);
    4220                 :            : }
    4221                 :            : EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_int64);
    4222                 :            : 
    4223                 :          0 : int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s)
    4224                 :            : {
    4225                 :            :         lockdep_assert_held(ctrl->handler->lock);
    4226                 :            : 
    4227                 :            :         /* It's a driver bug if this happens. */
    4228                 :          0 :         WARN_ON(ctrl->type != V4L2_CTRL_TYPE_STRING);
    4229                 :          0 :         strscpy(ctrl->p_new.p_char, s, ctrl->maximum + 1);
    4230                 :          0 :         return set_ctrl(NULL, ctrl, 0);
    4231                 :            : }
    4232                 :            : EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_string);
    4233                 :            : 
    4234                 :          0 : int __v4l2_ctrl_s_ctrl_area(struct v4l2_ctrl *ctrl,
    4235                 :            :                             const struct v4l2_area *area)
    4236                 :            : {
    4237                 :            :         lockdep_assert_held(ctrl->handler->lock);
    4238                 :            : 
    4239                 :            :         /* It's a driver bug if this happens. */
    4240                 :          0 :         WARN_ON(ctrl->type != V4L2_CTRL_TYPE_AREA);
    4241                 :          0 :         *ctrl->p_new.p_area = *area;
    4242                 :          0 :         return set_ctrl(NULL, ctrl, 0);
    4243                 :            : }
    4244                 :            : EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_area);
    4245                 :            : 
    4246                 :          0 : void v4l2_ctrl_request_complete(struct media_request *req,
    4247                 :            :                                 struct v4l2_ctrl_handler *main_hdl)
    4248                 :            : {
    4249                 :            :         struct media_request_object *obj;
    4250                 :            :         struct v4l2_ctrl_handler *hdl;
    4251                 :            :         struct v4l2_ctrl_ref *ref;
    4252                 :            : 
    4253                 :          0 :         if (!req || !main_hdl)
    4254                 :            :                 return;
    4255                 :            : 
    4256                 :            :         /*
    4257                 :            :          * Note that it is valid if nothing was found. It means
    4258                 :            :          * that this request doesn't have any controls and so just
    4259                 :            :          * wants to leave the controls unchanged.
    4260                 :            :          */
    4261                 :          0 :         obj = media_request_object_find(req, &req_ops, main_hdl);
    4262                 :          0 :         if (!obj)
    4263                 :            :                 return;
    4264                 :            :         hdl = container_of(obj, struct v4l2_ctrl_handler, req_obj);
    4265                 :            : 
    4266                 :          0 :         list_for_each_entry(ref, &hdl->ctrl_refs, node) {
    4267                 :          0 :                 struct v4l2_ctrl *ctrl = ref->ctrl;
    4268                 :          0 :                 struct v4l2_ctrl *master = ctrl->cluster[0];
    4269                 :            :                 unsigned int i;
    4270                 :            : 
    4271                 :          0 :                 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) {
    4272                 :          0 :                         ref->req = ref;
    4273                 :            : 
    4274                 :            :                         v4l2_ctrl_lock(master);
    4275                 :            :                         /* g_volatile_ctrl will update the current control values */
    4276                 :          0 :                         for (i = 0; i < master->ncontrols; i++)
    4277                 :          0 :                                 cur_to_new(master->cluster[i]);
    4278                 :          0 :                         call_op(master, g_volatile_ctrl);
    4279                 :          0 :                         new_to_req(ref);
    4280                 :            :                         v4l2_ctrl_unlock(master);
    4281                 :          0 :                         continue;
    4282                 :            :                 }
    4283                 :          0 :                 if (ref->req == ref)
    4284                 :          0 :                         continue;
    4285                 :            : 
    4286                 :            :                 v4l2_ctrl_lock(ctrl);
    4287                 :          0 :                 if (ref->req)
    4288                 :            :                         ptr_to_ptr(ctrl, ref->req->p_req, ref->p_req);
    4289                 :            :                 else
    4290                 :            :                         ptr_to_ptr(ctrl, ctrl->p_cur, ref->p_req);
    4291                 :            :                 v4l2_ctrl_unlock(ctrl);
    4292                 :            :         }
    4293                 :            : 
    4294                 :          0 :         mutex_lock(main_hdl->lock);
    4295                 :          0 :         WARN_ON(!hdl->request_is_queued);
    4296                 :          0 :         list_del_init(&hdl->requests_queued);
    4297                 :          0 :         hdl->request_is_queued = false;
    4298                 :          0 :         mutex_unlock(main_hdl->lock);
    4299                 :          0 :         media_request_object_complete(obj);
    4300                 :          0 :         media_request_object_put(obj);
    4301                 :            : }
    4302                 :            : EXPORT_SYMBOL(v4l2_ctrl_request_complete);
    4303                 :            : 
    4304                 :          0 : int v4l2_ctrl_request_setup(struct media_request *req,
    4305                 :            :                              struct v4l2_ctrl_handler *main_hdl)
    4306                 :            : {
    4307                 :            :         struct media_request_object *obj;
    4308                 :            :         struct v4l2_ctrl_handler *hdl;
    4309                 :            :         struct v4l2_ctrl_ref *ref;
    4310                 :            :         int ret = 0;
    4311                 :            : 
    4312                 :          0 :         if (!req || !main_hdl)
    4313                 :            :                 return 0;
    4314                 :            : 
    4315                 :          0 :         if (WARN_ON(req->state != MEDIA_REQUEST_STATE_QUEUED))
    4316                 :            :                 return -EBUSY;
    4317                 :            : 
    4318                 :            :         /*
    4319                 :            :          * Note that it is valid if nothing was found. It means
    4320                 :            :          * that this request doesn't have any controls and so just
    4321                 :            :          * wants to leave the controls unchanged.
    4322                 :            :          */
    4323                 :          0 :         obj = media_request_object_find(req, &req_ops, main_hdl);
    4324                 :          0 :         if (!obj)
    4325                 :            :                 return 0;
    4326                 :          0 :         if (obj->completed) {
    4327                 :          0 :                 media_request_object_put(obj);
    4328                 :          0 :                 return -EBUSY;
    4329                 :            :         }
    4330                 :          0 :         hdl = container_of(obj, struct v4l2_ctrl_handler, req_obj);
    4331                 :            : 
    4332                 :          0 :         list_for_each_entry(ref, &hdl->ctrl_refs, node)
    4333                 :          0 :                 ref->req_done = false;
    4334                 :            : 
    4335                 :          0 :         list_for_each_entry(ref, &hdl->ctrl_refs, node) {
    4336                 :          0 :                 struct v4l2_ctrl *ctrl = ref->ctrl;
    4337                 :          0 :                 struct v4l2_ctrl *master = ctrl->cluster[0];
    4338                 :            :                 bool have_new_data = false;
    4339                 :            :                 int i;
    4340                 :            : 
    4341                 :            :                 /*
    4342                 :            :                  * Skip if this control was already handled by a cluster.
    4343                 :            :                  * Skip button controls and read-only controls.
    4344                 :            :                  */
    4345                 :          0 :                 if (ref->req_done || ctrl->type == V4L2_CTRL_TYPE_BUTTON ||
    4346                 :          0 :                     (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY))
    4347                 :          0 :                         continue;
    4348                 :            : 
    4349                 :            :                 v4l2_ctrl_lock(master);
    4350                 :          0 :                 for (i = 0; i < master->ncontrols; i++) {
    4351                 :          0 :                         if (master->cluster[i]) {
    4352                 :          0 :                                 struct v4l2_ctrl_ref *r =
    4353                 :          0 :                                         find_ref(hdl, master->cluster[i]->id);
    4354                 :            : 
    4355                 :          0 :                                 if (r->req && r == r->req) {
    4356                 :            :                                         have_new_data = true;
    4357                 :            :                                         break;
    4358                 :            :                                 }
    4359                 :            :                         }
    4360                 :            :                 }
    4361                 :          0 :                 if (!have_new_data) {
    4362                 :            :                         v4l2_ctrl_unlock(master);
    4363                 :          0 :                         continue;
    4364                 :            :                 }
    4365                 :            : 
    4366                 :          0 :                 for (i = 0; i < master->ncontrols; i++) {
    4367                 :          0 :                         if (master->cluster[i]) {
    4368                 :          0 :                                 struct v4l2_ctrl_ref *r =
    4369                 :          0 :                                         find_ref(hdl, master->cluster[i]->id);
    4370                 :            : 
    4371                 :          0 :                                 req_to_new(r);
    4372                 :          0 :                                 master->cluster[i]->is_new = 1;
    4373                 :          0 :                                 r->req_done = true;
    4374                 :            :                         }
    4375                 :            :                 }
    4376                 :            :                 /*
    4377                 :            :                  * For volatile autoclusters that are currently in auto mode
    4378                 :            :                  * we need to discover if it will be set to manual mode.
    4379                 :            :                  * If so, then we have to copy the current volatile values
    4380                 :            :                  * first since those will become the new manual values (which
    4381                 :            :                  * may be overwritten by explicit new values from this set
    4382                 :            :                  * of controls).
    4383                 :            :                  */
    4384                 :          0 :                 if (master->is_auto && master->has_volatiles &&
    4385                 :            :                     !is_cur_manual(master)) {
    4386                 :          0 :                         s32 new_auto_val = *master->p_new.p_s32;
    4387                 :            : 
    4388                 :            :                         /*
    4389                 :            :                          * If the new value == the manual value, then copy
    4390                 :            :                          * the current volatile values.
    4391                 :            :                          */
    4392                 :          0 :                         if (new_auto_val == master->manual_mode_value)
    4393                 :          0 :                                 update_from_auto_cluster(master);
    4394                 :            :                 }
    4395                 :            : 
    4396                 :          0 :                 ret = try_or_set_cluster(NULL, master, true, 0);
    4397                 :            :                 v4l2_ctrl_unlock(master);
    4398                 :            : 
    4399                 :          0 :                 if (ret)
    4400                 :            :                         break;
    4401                 :            :         }
    4402                 :            : 
    4403                 :          0 :         media_request_object_put(obj);
    4404                 :          0 :         return ret;
    4405                 :            : }
    4406                 :            : EXPORT_SYMBOL(v4l2_ctrl_request_setup);
    4407                 :            : 
    4408                 :          0 : void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv)
    4409                 :            : {
    4410                 :          0 :         if (ctrl == NULL)
    4411                 :            :                 return;
    4412                 :          0 :         if (notify == NULL) {
    4413                 :          0 :                 ctrl->call_notify = 0;
    4414                 :          0 :                 return;
    4415                 :            :         }
    4416                 :          0 :         if (WARN_ON(ctrl->handler->notify && ctrl->handler->notify != notify))
    4417                 :            :                 return;
    4418                 :          0 :         ctrl->handler->notify = notify;
    4419                 :          0 :         ctrl->handler->notify_priv = priv;
    4420                 :          0 :         ctrl->call_notify = 1;
    4421                 :            : }
    4422                 :            : EXPORT_SYMBOL(v4l2_ctrl_notify);
    4423                 :            : 
    4424                 :          0 : int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
    4425                 :            :                         s64 min, s64 max, u64 step, s64 def)
    4426                 :            : {
    4427                 :            :         bool value_changed;
    4428                 :            :         bool range_changed = false;
    4429                 :            :         int ret;
    4430                 :            : 
    4431                 :            :         lockdep_assert_held(ctrl->handler->lock);
    4432                 :            : 
    4433                 :          0 :         switch (ctrl->type) {
    4434                 :            :         case V4L2_CTRL_TYPE_INTEGER:
    4435                 :            :         case V4L2_CTRL_TYPE_INTEGER64:
    4436                 :            :         case V4L2_CTRL_TYPE_BOOLEAN:
    4437                 :            :         case V4L2_CTRL_TYPE_MENU:
    4438                 :            :         case V4L2_CTRL_TYPE_INTEGER_MENU:
    4439                 :            :         case V4L2_CTRL_TYPE_BITMASK:
    4440                 :            :         case V4L2_CTRL_TYPE_U8:
    4441                 :            :         case V4L2_CTRL_TYPE_U16:
    4442                 :            :         case V4L2_CTRL_TYPE_U32:
    4443                 :          0 :                 if (ctrl->is_array)
    4444                 :            :                         return -EINVAL;
    4445                 :          0 :                 ret = check_range(ctrl->type, min, max, step, def);
    4446                 :          0 :                 if (ret)
    4447                 :            :                         return ret;
    4448                 :            :                 break;
    4449                 :            :         default:
    4450                 :            :                 return -EINVAL;
    4451                 :            :         }
    4452                 :          0 :         if ((ctrl->minimum != min) || (ctrl->maximum != max) ||
    4453                 :          0 :                 (ctrl->step != step) || ctrl->default_value != def) {
    4454                 :            :                 range_changed = true;
    4455                 :          0 :                 ctrl->minimum = min;
    4456                 :          0 :                 ctrl->maximum = max;
    4457                 :          0 :                 ctrl->step = step;
    4458                 :          0 :                 ctrl->default_value = def;
    4459                 :            :         }
    4460                 :          0 :         cur_to_new(ctrl);
    4461                 :          0 :         if (validate_new(ctrl, ctrl->p_new)) {
    4462                 :          0 :                 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
    4463                 :          0 :                         *ctrl->p_new.p_s64 = def;
    4464                 :            :                 else
    4465                 :          0 :                         *ctrl->p_new.p_s32 = def;
    4466                 :            :         }
    4467                 :            : 
    4468                 :          0 :         if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
    4469                 :          0 :                 value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64;
    4470                 :            :         else
    4471                 :          0 :                 value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32;
    4472                 :          0 :         if (value_changed)
    4473                 :          0 :                 ret = set_ctrl(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
    4474                 :          0 :         else if (range_changed)
    4475                 :          0 :                 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
    4476                 :          0 :         return ret;
    4477                 :            : }
    4478                 :            : EXPORT_SYMBOL(__v4l2_ctrl_modify_range);
    4479                 :            : 
    4480                 :          0 : static int v4l2_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems)
    4481                 :            : {
    4482                 :          0 :         struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id);
    4483                 :            : 
    4484                 :          0 :         if (ctrl == NULL)
    4485                 :            :                 return -EINVAL;
    4486                 :            : 
    4487                 :            :         v4l2_ctrl_lock(ctrl);
    4488                 :          0 :         list_add_tail(&sev->node, &ctrl->ev_subs);
    4489                 :          0 :         if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS &&
    4490                 :          0 :             (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) {
    4491                 :            :                 struct v4l2_event ev;
    4492                 :            :                 u32 changes = V4L2_EVENT_CTRL_CH_FLAGS;
    4493                 :            : 
    4494                 :          0 :                 if (!(ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY))
    4495                 :            :                         changes |= V4L2_EVENT_CTRL_CH_VALUE;
    4496                 :          0 :                 fill_event(&ev, ctrl, changes);
    4497                 :            :                 /* Mark the queue as active, allowing this initial
    4498                 :            :                    event to be accepted. */
    4499                 :          0 :                 sev->elems = elems;
    4500                 :          0 :                 v4l2_event_queue_fh(sev->fh, &ev);
    4501                 :            :         }
    4502                 :            :         v4l2_ctrl_unlock(ctrl);
    4503                 :          0 :         return 0;
    4504                 :            : }
    4505                 :            : 
    4506                 :          0 : static void v4l2_ctrl_del_event(struct v4l2_subscribed_event *sev)
    4507                 :            : {
    4508                 :          0 :         struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id);
    4509                 :            : 
    4510                 :          0 :         if (ctrl == NULL)
    4511                 :          0 :                 return;
    4512                 :            : 
    4513                 :            :         v4l2_ctrl_lock(ctrl);
    4514                 :            :         list_del(&sev->node);
    4515                 :            :         v4l2_ctrl_unlock(ctrl);
    4516                 :            : }
    4517                 :            : 
    4518                 :          0 : void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new)
    4519                 :            : {
    4520                 :          0 :         u32 old_changes = old->u.ctrl.changes;
    4521                 :            : 
    4522                 :          0 :         old->u.ctrl = new->u.ctrl;
    4523                 :          0 :         old->u.ctrl.changes |= old_changes;
    4524                 :          0 : }
    4525                 :            : EXPORT_SYMBOL(v4l2_ctrl_replace);
    4526                 :            : 
    4527                 :          0 : void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new)
    4528                 :            : {
    4529                 :          0 :         new->u.ctrl.changes |= old->u.ctrl.changes;
    4530                 :          0 : }
    4531                 :            : EXPORT_SYMBOL(v4l2_ctrl_merge);
    4532                 :            : 
    4533                 :            : const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops = {
    4534                 :            :         .add = v4l2_ctrl_add_event,
    4535                 :            :         .del = v4l2_ctrl_del_event,
    4536                 :            :         .replace = v4l2_ctrl_replace,
    4537                 :            :         .merge = v4l2_ctrl_merge,
    4538                 :            : };
    4539                 :            : EXPORT_SYMBOL(v4l2_ctrl_sub_ev_ops);
    4540                 :            : 
    4541                 :          0 : int v4l2_ctrl_log_status(struct file *file, void *fh)
    4542                 :            : {
    4543                 :          0 :         struct video_device *vfd = video_devdata(file);
    4544                 :          0 :         struct v4l2_fh *vfh = file->private_data;
    4545                 :            : 
    4546                 :          0 :         if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) && vfd->v4l2_dev)
    4547                 :          0 :                 v4l2_ctrl_handler_log_status(vfh->ctrl_handler,
    4548                 :          0 :                         vfd->v4l2_dev->name);
    4549                 :          0 :         return 0;
    4550                 :            : }
    4551                 :            : EXPORT_SYMBOL(v4l2_ctrl_log_status);
    4552                 :            : 
    4553                 :          0 : int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
    4554                 :            :                                 const struct v4l2_event_subscription *sub)
    4555                 :            : {
    4556                 :          0 :         if (sub->type == V4L2_EVENT_CTRL)
    4557                 :          0 :                 return v4l2_event_subscribe(fh, sub, 0, &v4l2_ctrl_sub_ev_ops);
    4558                 :            :         return -EINVAL;
    4559                 :            : }
    4560                 :            : EXPORT_SYMBOL(v4l2_ctrl_subscribe_event);
    4561                 :            : 
    4562                 :          0 : int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
    4563                 :            :                                      struct v4l2_event_subscription *sub)
    4564                 :            : {
    4565                 :          0 :         if (!sd->ctrl_handler)
    4566                 :            :                 return -EINVAL;
    4567                 :          0 :         return v4l2_ctrl_subscribe_event(fh, sub);
    4568                 :            : }
    4569                 :            : EXPORT_SYMBOL(v4l2_ctrl_subdev_subscribe_event);
    4570                 :            : 
    4571                 :          0 : __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait)
    4572                 :            : {
    4573                 :          0 :         struct v4l2_fh *fh = file->private_data;
    4574                 :            : 
    4575                 :          0 :         poll_wait(file, &fh->wait, wait);
    4576                 :          0 :         if (v4l2_event_pending(fh))
    4577                 :            :                 return EPOLLPRI;
    4578                 :          0 :         return 0;
    4579                 :            : }
    4580                 :            : EXPORT_SYMBOL(v4l2_ctrl_poll);
    4581                 :            : 
    4582                 :          0 : int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
    4583                 :            :                                     const struct v4l2_ctrl_ops *ctrl_ops,
    4584                 :            :                                     const struct v4l2_fwnode_device_properties *p)
    4585                 :            : {
    4586                 :          0 :         if (p->orientation != V4L2_FWNODE_PROPERTY_UNSET) {
    4587                 :            :                 u32 orientation_ctrl;
    4588                 :            : 
    4589                 :          0 :                 switch (p->orientation) {
    4590                 :            :                 case V4L2_FWNODE_ORIENTATION_FRONT:
    4591                 :            :                         orientation_ctrl = V4L2_CAMERA_ORIENTATION_FRONT;
    4592                 :            :                         break;
    4593                 :            :                 case V4L2_FWNODE_ORIENTATION_BACK:
    4594                 :            :                         orientation_ctrl = V4L2_CAMERA_ORIENTATION_BACK;
    4595                 :          0 :                         break;
    4596                 :            :                 case V4L2_FWNODE_ORIENTATION_EXTERNAL:
    4597                 :            :                         orientation_ctrl = V4L2_CAMERA_ORIENTATION_EXTERNAL;
    4598                 :          0 :                         break;
    4599                 :            :                 default:
    4600                 :            :                         return -EINVAL;
    4601                 :            :                 }
    4602                 :          0 :                 if (!v4l2_ctrl_new_std_menu(hdl, ctrl_ops,
    4603                 :            :                                             V4L2_CID_CAMERA_ORIENTATION,
    4604                 :            :                                             V4L2_CAMERA_ORIENTATION_EXTERNAL, 0,
    4605                 :            :                                             orientation_ctrl))
    4606                 :          0 :                         return hdl->error;
    4607                 :            :         }
    4608                 :            : 
    4609                 :          0 :         if (p->rotation != V4L2_FWNODE_PROPERTY_UNSET) {
    4610                 :          0 :                 if (!v4l2_ctrl_new_std(hdl, ctrl_ops,
    4611                 :            :                                        V4L2_CID_CAMERA_SENSOR_ROTATION,
    4612                 :            :                                        p->rotation, p->rotation, 1,
    4613                 :            :                                        p->rotation))
    4614                 :          0 :                         return hdl->error;
    4615                 :            :         }
    4616                 :            : 
    4617                 :          0 :         return hdl->error;
    4618                 :            : }
    4619                 :            : EXPORT_SYMBOL(v4l2_ctrl_new_fwnode_properties);
    

Generated by: LCOV version 1.14