Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1 | /* |
| 2 | V4L2 controls framework implementation. |
| 3 | |
| 4 | Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl> |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <linux/ctype.h> |
Randy Dunlap | 2b80163 | 2010-08-09 14:56:35 -0300 | [diff] [blame] | 22 | #include <linux/slab.h> |
Paul Gortmaker | 35a2463 | 2011-08-01 15:26:38 -0400 | [diff] [blame^] | 23 | #include <linux/export.h> |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 24 | #include <media/v4l2-ioctl.h> |
| 25 | #include <media/v4l2-device.h> |
| 26 | #include <media/v4l2-ctrls.h> |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 27 | #include <media/v4l2-event.h> |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 28 | #include <media/v4l2-dev.h> |
| 29 | |
Hans Verkuil | ddac5c1 | 2011-06-10 05:43:34 -0300 | [diff] [blame] | 30 | #define has_op(master, op) \ |
| 31 | (master->ops && master->ops->op) |
Hans Verkuil | 54c911e | 2011-05-25 06:04:58 -0300 | [diff] [blame] | 32 | #define call_op(master, op) \ |
Hans Verkuil | ddac5c1 | 2011-06-10 05:43:34 -0300 | [diff] [blame] | 33 | (has_op(master, op) ? master->ops->op(master) : 0) |
Hans Verkuil | 54c911e | 2011-05-25 06:04:58 -0300 | [diff] [blame] | 34 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 35 | /* Internal temporary helper struct, one for each v4l2_ext_control */ |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 36 | struct v4l2_ctrl_helper { |
| 37 | /* Pointer to the control reference of the master control */ |
| 38 | struct v4l2_ctrl_ref *mref; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 39 | /* The control corresponding to the v4l2_ext_control ID field. */ |
| 40 | struct v4l2_ctrl *ctrl; |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 41 | /* v4l2_ext_control index of the next control belonging to the |
| 42 | same cluster, or 0 if there isn't any. */ |
| 43 | u32 next; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 44 | }; |
| 45 | |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 46 | /* Small helper function to determine if the autocluster is set to manual |
| 47 | mode. In that case the is_volatile flag should be ignored. */ |
| 48 | static bool is_cur_manual(const struct v4l2_ctrl *master) |
| 49 | { |
| 50 | return master->is_auto && master->cur.val == master->manual_mode_value; |
| 51 | } |
| 52 | |
| 53 | /* Same as above, but this checks the against the new value instead of the |
| 54 | current value. */ |
| 55 | static bool is_new_manual(const struct v4l2_ctrl *master) |
| 56 | { |
| 57 | return master->is_auto && master->val == master->manual_mode_value; |
| 58 | } |
| 59 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 60 | /* Returns NULL or a character pointer array containing the menu for |
| 61 | the given control ID. The pointer array ends with a NULL pointer. |
| 62 | An empty string signifies a menu entry that is invalid. This allows |
| 63 | drivers to disable certain options if it is not supported. */ |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 64 | const char * const *v4l2_ctrl_get_menu(u32 id) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 65 | { |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 66 | static const char * const mpeg_audio_sampling_freq[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 67 | "44.1 kHz", |
| 68 | "48 kHz", |
| 69 | "32 kHz", |
| 70 | NULL |
| 71 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 72 | static const char * const mpeg_audio_encoding[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 73 | "MPEG-1/2 Layer I", |
| 74 | "MPEG-1/2 Layer II", |
| 75 | "MPEG-1/2 Layer III", |
| 76 | "MPEG-2/4 AAC", |
| 77 | "AC-3", |
| 78 | NULL |
| 79 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 80 | static const char * const mpeg_audio_l1_bitrate[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 81 | "32 kbps", |
| 82 | "64 kbps", |
| 83 | "96 kbps", |
| 84 | "128 kbps", |
| 85 | "160 kbps", |
| 86 | "192 kbps", |
| 87 | "224 kbps", |
| 88 | "256 kbps", |
| 89 | "288 kbps", |
| 90 | "320 kbps", |
| 91 | "352 kbps", |
| 92 | "384 kbps", |
| 93 | "416 kbps", |
| 94 | "448 kbps", |
| 95 | NULL |
| 96 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 97 | static const char * const mpeg_audio_l2_bitrate[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 98 | "32 kbps", |
| 99 | "48 kbps", |
| 100 | "56 kbps", |
| 101 | "64 kbps", |
| 102 | "80 kbps", |
| 103 | "96 kbps", |
| 104 | "112 kbps", |
| 105 | "128 kbps", |
| 106 | "160 kbps", |
| 107 | "192 kbps", |
| 108 | "224 kbps", |
| 109 | "256 kbps", |
| 110 | "320 kbps", |
| 111 | "384 kbps", |
| 112 | NULL |
| 113 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 114 | static const char * const mpeg_audio_l3_bitrate[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 115 | "32 kbps", |
| 116 | "40 kbps", |
| 117 | "48 kbps", |
| 118 | "56 kbps", |
| 119 | "64 kbps", |
| 120 | "80 kbps", |
| 121 | "96 kbps", |
| 122 | "112 kbps", |
| 123 | "128 kbps", |
| 124 | "160 kbps", |
| 125 | "192 kbps", |
| 126 | "224 kbps", |
| 127 | "256 kbps", |
| 128 | "320 kbps", |
| 129 | NULL |
| 130 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 131 | static const char * const mpeg_audio_ac3_bitrate[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 132 | "32 kbps", |
| 133 | "40 kbps", |
| 134 | "48 kbps", |
| 135 | "56 kbps", |
| 136 | "64 kbps", |
| 137 | "80 kbps", |
| 138 | "96 kbps", |
| 139 | "112 kbps", |
| 140 | "128 kbps", |
| 141 | "160 kbps", |
| 142 | "192 kbps", |
| 143 | "224 kbps", |
| 144 | "256 kbps", |
| 145 | "320 kbps", |
| 146 | "384 kbps", |
| 147 | "448 kbps", |
| 148 | "512 kbps", |
| 149 | "576 kbps", |
| 150 | "640 kbps", |
| 151 | NULL |
| 152 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 153 | static const char * const mpeg_audio_mode[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 154 | "Stereo", |
| 155 | "Joint Stereo", |
| 156 | "Dual", |
| 157 | "Mono", |
| 158 | NULL |
| 159 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 160 | static const char * const mpeg_audio_mode_extension[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 161 | "Bound 4", |
| 162 | "Bound 8", |
| 163 | "Bound 12", |
| 164 | "Bound 16", |
| 165 | NULL |
| 166 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 167 | static const char * const mpeg_audio_emphasis[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 168 | "No Emphasis", |
| 169 | "50/15 us", |
| 170 | "CCITT J17", |
| 171 | NULL |
| 172 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 173 | static const char * const mpeg_audio_crc[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 174 | "No CRC", |
| 175 | "16-bit CRC", |
| 176 | NULL |
| 177 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 178 | static const char * const mpeg_video_encoding[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 179 | "MPEG-1", |
| 180 | "MPEG-2", |
| 181 | "MPEG-4 AVC", |
| 182 | NULL |
| 183 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 184 | static const char * const mpeg_video_aspect[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 185 | "1x1", |
| 186 | "4x3", |
| 187 | "16x9", |
| 188 | "2.21x1", |
| 189 | NULL |
| 190 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 191 | static const char * const mpeg_video_bitrate_mode[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 192 | "Variable Bitrate", |
| 193 | "Constant Bitrate", |
| 194 | NULL |
| 195 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 196 | static const char * const mpeg_stream_type[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 197 | "MPEG-2 Program Stream", |
| 198 | "MPEG-2 Transport Stream", |
| 199 | "MPEG-1 System Stream", |
| 200 | "MPEG-2 DVD-compatible Stream", |
| 201 | "MPEG-1 VCD-compatible Stream", |
| 202 | "MPEG-2 SVCD-compatible Stream", |
| 203 | NULL |
| 204 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 205 | static const char * const mpeg_stream_vbi_fmt[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 206 | "No VBI", |
Kamil Debski | 064f509 | 2011-06-14 10:46:22 -0300 | [diff] [blame] | 207 | "Private Packet, IVTV Format", |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 208 | NULL |
| 209 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 210 | static const char * const camera_power_line_frequency[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 211 | "Disabled", |
| 212 | "50 Hz", |
| 213 | "60 Hz", |
| 214 | NULL |
| 215 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 216 | static const char * const camera_exposure_auto[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 217 | "Auto Mode", |
| 218 | "Manual Mode", |
| 219 | "Shutter Priority Mode", |
| 220 | "Aperture Priority Mode", |
| 221 | NULL |
| 222 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 223 | static const char * const colorfx[] = { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 224 | "None", |
| 225 | "Black & White", |
| 226 | "Sepia", |
| 227 | "Negative", |
| 228 | "Emboss", |
| 229 | "Sketch", |
Kamil Debski | 064f509 | 2011-06-14 10:46:22 -0300 | [diff] [blame] | 230 | "Sky Blue", |
| 231 | "Grass Green", |
| 232 | "Skin Whiten", |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 233 | "Vivid", |
| 234 | NULL |
| 235 | }; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 236 | static const char * const tune_preemphasis[] = { |
Kamil Debski | 064f509 | 2011-06-14 10:46:22 -0300 | [diff] [blame] | 237 | "No Preemphasis", |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 238 | "50 useconds", |
| 239 | "75 useconds", |
| 240 | NULL, |
| 241 | }; |
Kamil Debski | 064f509 | 2011-06-14 10:46:22 -0300 | [diff] [blame] | 242 | static const char * const header_mode[] = { |
| 243 | "Separate Buffer", |
| 244 | "Joined With 1st Frame", |
| 245 | NULL, |
| 246 | }; |
| 247 | static const char * const multi_slice[] = { |
| 248 | "Single", |
| 249 | "Max Macroblocks", |
| 250 | "Max Bytes", |
| 251 | NULL, |
| 252 | }; |
| 253 | static const char * const entropy_mode[] = { |
| 254 | "CAVLC", |
| 255 | "CABAC", |
| 256 | NULL, |
| 257 | }; |
| 258 | static const char * const mpeg_h264_level[] = { |
| 259 | "1", |
| 260 | "1b", |
| 261 | "1.1", |
| 262 | "1.2", |
| 263 | "1.3", |
| 264 | "2", |
| 265 | "2.1", |
| 266 | "2.2", |
| 267 | "3", |
| 268 | "3.1", |
| 269 | "3.2", |
| 270 | "4", |
| 271 | "4.1", |
| 272 | "4.2", |
| 273 | "5", |
| 274 | "5.1", |
| 275 | NULL, |
| 276 | }; |
| 277 | static const char * const h264_loop_filter[] = { |
| 278 | "Enabled", |
| 279 | "Disabled", |
| 280 | "Disabled at Slice Boundary", |
| 281 | NULL, |
| 282 | }; |
| 283 | static const char * const h264_profile[] = { |
| 284 | "Baseline", |
| 285 | "Constrained Baseline", |
| 286 | "Main", |
| 287 | "Extended", |
| 288 | "High", |
| 289 | "High 10", |
| 290 | "High 422", |
| 291 | "High 444 Predictive", |
| 292 | "High 10 Intra", |
| 293 | "High 422 Intra", |
| 294 | "High 444 Intra", |
| 295 | "CAVLC 444 Intra", |
| 296 | "Scalable Baseline", |
| 297 | "Scalable High", |
| 298 | "Scalable High Intra", |
| 299 | "Multiview High", |
| 300 | NULL, |
| 301 | }; |
| 302 | static const char * const vui_sar_idc[] = { |
| 303 | "Unspecified", |
| 304 | "1:1", |
| 305 | "12:11", |
| 306 | "10:11", |
| 307 | "16:11", |
| 308 | "40:33", |
| 309 | "24:11", |
| 310 | "20:11", |
| 311 | "32:11", |
| 312 | "80:33", |
| 313 | "18:11", |
| 314 | "15:11", |
| 315 | "64:33", |
| 316 | "160:99", |
| 317 | "4:3", |
| 318 | "3:2", |
| 319 | "2:1", |
| 320 | "Extended SAR", |
| 321 | NULL, |
| 322 | }; |
| 323 | static const char * const mpeg_mpeg4_level[] = { |
| 324 | "0", |
| 325 | "0b", |
| 326 | "1", |
| 327 | "2", |
| 328 | "3", |
| 329 | "3b", |
| 330 | "4", |
| 331 | "5", |
| 332 | NULL, |
| 333 | }; |
| 334 | static const char * const mpeg4_profile[] = { |
| 335 | "Simple", |
| 336 | "Adcanved Simple", |
| 337 | "Core", |
| 338 | "Simple Scalable", |
| 339 | "Advanced Coding Efficency", |
| 340 | NULL, |
| 341 | }; |
| 342 | |
Sakari Ailus | 0b159ac | 2011-03-21 12:52:51 -0300 | [diff] [blame] | 343 | static const char * const flash_led_mode[] = { |
| 344 | "Off", |
| 345 | "Flash", |
| 346 | "Torch", |
| 347 | NULL, |
| 348 | }; |
| 349 | static const char * const flash_strobe_source[] = { |
| 350 | "Software", |
| 351 | "External", |
| 352 | NULL, |
| 353 | }; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 354 | |
| 355 | switch (id) { |
| 356 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: |
| 357 | return mpeg_audio_sampling_freq; |
| 358 | case V4L2_CID_MPEG_AUDIO_ENCODING: |
| 359 | return mpeg_audio_encoding; |
| 360 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: |
| 361 | return mpeg_audio_l1_bitrate; |
| 362 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: |
| 363 | return mpeg_audio_l2_bitrate; |
| 364 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: |
| 365 | return mpeg_audio_l3_bitrate; |
| 366 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: |
| 367 | return mpeg_audio_ac3_bitrate; |
| 368 | case V4L2_CID_MPEG_AUDIO_MODE: |
| 369 | return mpeg_audio_mode; |
| 370 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: |
| 371 | return mpeg_audio_mode_extension; |
| 372 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: |
| 373 | return mpeg_audio_emphasis; |
| 374 | case V4L2_CID_MPEG_AUDIO_CRC: |
| 375 | return mpeg_audio_crc; |
| 376 | case V4L2_CID_MPEG_VIDEO_ENCODING: |
| 377 | return mpeg_video_encoding; |
| 378 | case V4L2_CID_MPEG_VIDEO_ASPECT: |
| 379 | return mpeg_video_aspect; |
| 380 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: |
| 381 | return mpeg_video_bitrate_mode; |
| 382 | case V4L2_CID_MPEG_STREAM_TYPE: |
| 383 | return mpeg_stream_type; |
| 384 | case V4L2_CID_MPEG_STREAM_VBI_FMT: |
| 385 | return mpeg_stream_vbi_fmt; |
| 386 | case V4L2_CID_POWER_LINE_FREQUENCY: |
| 387 | return camera_power_line_frequency; |
| 388 | case V4L2_CID_EXPOSURE_AUTO: |
| 389 | return camera_exposure_auto; |
| 390 | case V4L2_CID_COLORFX: |
| 391 | return colorfx; |
| 392 | case V4L2_CID_TUNE_PREEMPHASIS: |
| 393 | return tune_preemphasis; |
Sakari Ailus | 0b159ac | 2011-03-21 12:52:51 -0300 | [diff] [blame] | 394 | case V4L2_CID_FLASH_LED_MODE: |
| 395 | return flash_led_mode; |
| 396 | case V4L2_CID_FLASH_STROBE_SOURCE: |
| 397 | return flash_strobe_source; |
Kamil Debski | 064f509 | 2011-06-14 10:46:22 -0300 | [diff] [blame] | 398 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: |
| 399 | return header_mode; |
| 400 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: |
| 401 | return multi_slice; |
| 402 | case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: |
| 403 | return entropy_mode; |
| 404 | case V4L2_CID_MPEG_VIDEO_H264_LEVEL: |
| 405 | return mpeg_h264_level; |
| 406 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: |
| 407 | return h264_loop_filter; |
| 408 | case V4L2_CID_MPEG_VIDEO_H264_PROFILE: |
| 409 | return h264_profile; |
| 410 | case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC: |
| 411 | return vui_sar_idc; |
| 412 | case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL: |
| 413 | return mpeg_mpeg4_level; |
| 414 | case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE: |
| 415 | return mpeg4_profile; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 416 | default: |
| 417 | return NULL; |
| 418 | } |
| 419 | } |
| 420 | EXPORT_SYMBOL(v4l2_ctrl_get_menu); |
| 421 | |
| 422 | /* Return the control name. */ |
| 423 | const char *v4l2_ctrl_get_name(u32 id) |
| 424 | { |
| 425 | switch (id) { |
| 426 | /* USER controls */ |
Hans Verkuil | 6c8d611 | 2010-04-25 19:21:00 -0300 | [diff] [blame] | 427 | /* Keep the order of the 'case's the same as in videodev2.h! */ |
Mauro Carvalho Chehab | 6dd5aff | 2010-08-06 09:57:02 -0300 | [diff] [blame] | 428 | case V4L2_CID_USER_CLASS: return "User Controls"; |
| 429 | case V4L2_CID_BRIGHTNESS: return "Brightness"; |
| 430 | case V4L2_CID_CONTRAST: return "Contrast"; |
| 431 | case V4L2_CID_SATURATION: return "Saturation"; |
| 432 | case V4L2_CID_HUE: return "Hue"; |
| 433 | case V4L2_CID_AUDIO_VOLUME: return "Volume"; |
| 434 | case V4L2_CID_AUDIO_BALANCE: return "Balance"; |
| 435 | case V4L2_CID_AUDIO_BASS: return "Bass"; |
| 436 | case V4L2_CID_AUDIO_TREBLE: return "Treble"; |
| 437 | case V4L2_CID_AUDIO_MUTE: return "Mute"; |
| 438 | case V4L2_CID_AUDIO_LOUDNESS: return "Loudness"; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 439 | case V4L2_CID_BLACK_LEVEL: return "Black Level"; |
| 440 | case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic"; |
| 441 | case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance"; |
| 442 | case V4L2_CID_RED_BALANCE: return "Red Balance"; |
| 443 | case V4L2_CID_BLUE_BALANCE: return "Blue Balance"; |
| 444 | case V4L2_CID_GAMMA: return "Gamma"; |
| 445 | case V4L2_CID_EXPOSURE: return "Exposure"; |
| 446 | case V4L2_CID_AUTOGAIN: return "Gain, Automatic"; |
| 447 | case V4L2_CID_GAIN: return "Gain"; |
| 448 | case V4L2_CID_HFLIP: return "Horizontal Flip"; |
| 449 | case V4L2_CID_VFLIP: return "Vertical Flip"; |
| 450 | case V4L2_CID_HCENTER: return "Horizontal Center"; |
| 451 | case V4L2_CID_VCENTER: return "Vertical Center"; |
| 452 | case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency"; |
| 453 | case V4L2_CID_HUE_AUTO: return "Hue, Automatic"; |
| 454 | case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature"; |
| 455 | case V4L2_CID_SHARPNESS: return "Sharpness"; |
| 456 | case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation"; |
| 457 | case V4L2_CID_CHROMA_AGC: return "Chroma AGC"; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 458 | case V4L2_CID_COLOR_KILLER: return "Color Killer"; |
| 459 | case V4L2_CID_COLORFX: return "Color Effects"; |
| 460 | case V4L2_CID_AUTOBRIGHTNESS: return "Brightness, Automatic"; |
| 461 | case V4L2_CID_BAND_STOP_FILTER: return "Band-Stop Filter"; |
| 462 | case V4L2_CID_ROTATE: return "Rotate"; |
| 463 | case V4L2_CID_BG_COLOR: return "Background Color"; |
Hans Verkuil | 6c8d611 | 2010-04-25 19:21:00 -0300 | [diff] [blame] | 464 | case V4L2_CID_CHROMA_GAIN: return "Chroma Gain"; |
Jean-François Moine | 008d35f | 2010-09-13 07:04:49 -0300 | [diff] [blame] | 465 | case V4L2_CID_ILLUMINATORS_1: return "Illuminator 1"; |
| 466 | case V4L2_CID_ILLUMINATORS_2: return "Illuminator 2"; |
Kamil Debski | 064f509 | 2011-06-14 10:46:22 -0300 | [diff] [blame] | 467 | case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE: return "Minimum Number of Capture Buffers"; |
| 468 | case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT: return "Minimum Number of Output Buffers"; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 469 | |
| 470 | /* MPEG controls */ |
Hans Verkuil | 6c8d611 | 2010-04-25 19:21:00 -0300 | [diff] [blame] | 471 | /* Keep the order of the 'case's the same as in videodev2.h! */ |
Mauro Carvalho Chehab | 6dd5aff | 2010-08-06 09:57:02 -0300 | [diff] [blame] | 472 | case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls"; |
| 473 | case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type"; |
| 474 | case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID"; |
| 475 | case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID"; |
| 476 | case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID"; |
| 477 | case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID"; |
Hans Verkuil | 6c8d611 | 2010-04-25 19:21:00 -0300 | [diff] [blame] | 478 | case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID"; |
| 479 | case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID"; |
| 480 | case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format"; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 481 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency"; |
Mauro Carvalho Chehab | 6dd5aff | 2010-08-06 09:57:02 -0300 | [diff] [blame] | 482 | case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding"; |
| 483 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate"; |
| 484 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate"; |
| 485 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate"; |
| 486 | case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode"; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 487 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension"; |
Mauro Carvalho Chehab | 6dd5aff | 2010-08-06 09:57:02 -0300 | [diff] [blame] | 488 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis"; |
| 489 | case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC"; |
| 490 | case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute"; |
| 491 | case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate"; |
| 492 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate"; |
| 493 | case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding"; |
| 494 | case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect"; |
| 495 | case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames"; |
| 496 | case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size"; |
| 497 | case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure"; |
| 498 | case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown"; |
| 499 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode"; |
| 500 | case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate"; |
| 501 | case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate"; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 502 | case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation"; |
Mauro Carvalho Chehab | 6dd5aff | 2010-08-06 09:57:02 -0300 | [diff] [blame] | 503 | case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute"; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 504 | case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV"; |
Kamil Debski | 064f509 | 2011-06-14 10:46:22 -0300 | [diff] [blame] | 505 | case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE: return "Decoder Slice Interface"; |
| 506 | case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER: return "MPEG4 Loop Filter Enable"; |
| 507 | case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB: return "The Number of Intra Refresh MBs"; |
| 508 | case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE: return "Frame Level Rate Control Enable"; |
| 509 | case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE: return "H264 MB Level Rate Control"; |
| 510 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: return "Sequence Header Mode"; |
| 511 | case V4L2_CID_MPEG_VIDEO_MAX_REF_PIC: return "The Max Number of Reference Picture"; |
| 512 | case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP: return "H263 I-Frame QP Value"; |
| 513 | case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP: return "H263 P frame QP Value"; |
| 514 | case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP: return "H263 B frame QP Value"; |
| 515 | case V4L2_CID_MPEG_VIDEO_H263_MIN_QP: return "H263 Minimum QP Value"; |
| 516 | case V4L2_CID_MPEG_VIDEO_H263_MAX_QP: return "H263 Maximum QP Value"; |
| 517 | case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: return "H264 I-Frame QP Value"; |
| 518 | case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: return "H264 P frame QP Value"; |
| 519 | case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP: return "H264 B frame QP Value"; |
| 520 | case V4L2_CID_MPEG_VIDEO_H264_MAX_QP: return "H264 Maximum QP Value"; |
| 521 | case V4L2_CID_MPEG_VIDEO_H264_MIN_QP: return "H264 Minimum QP Value"; |
| 522 | case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM: return "H264 8x8 Transform Enable"; |
| 523 | case V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE: return "H264 CPB Buffer Size"; |
| 524 | case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: return "H264 Entorpy Mode"; |
| 525 | case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD: return "H264 I Period"; |
| 526 | case V4L2_CID_MPEG_VIDEO_H264_LEVEL: return "H264 Level"; |
| 527 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA: return "H264 Loop Filter Alpha Offset"; |
| 528 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA: return "H264 Loop Filter Beta Offset"; |
| 529 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: return "H264 Loop Filter Mode"; |
| 530 | case V4L2_CID_MPEG_VIDEO_H264_PROFILE: return "H264 Profile"; |
| 531 | case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT: return "Vertical Size of SAR"; |
| 532 | case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH: return "Horizontal Size of SAR"; |
| 533 | case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE: return "Aspect Ratio VUI Enable"; |
| 534 | case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC: return "VUI Aspect Ratio IDC"; |
| 535 | case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP: return "MPEG4 I-Frame QP Value"; |
| 536 | case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP: return "MPEG4 P frame QP Value"; |
| 537 | case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP: return "MPEG4 B frame QP Value"; |
| 538 | case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP: return "MPEG4 Minimum QP Value"; |
| 539 | case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP: return "MPEG4 Maximum QP Value"; |
| 540 | case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL: return "MPEG4 Level"; |
| 541 | case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE: return "MPEG4 Profile"; |
| 542 | case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL: return "Quarter Pixel Search Enable"; |
| 543 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: return "The Maximum Bytes Per Slice"; |
| 544 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: return "The Number of MB in a Slice"; |
| 545 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: return "The Slice Partitioning Method"; |
| 546 | case V4L2_CID_MPEG_VIDEO_VBV_SIZE: return "VBV Buffer Size"; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 547 | |
| 548 | /* CAMERA controls */ |
Hans Verkuil | 6c8d611 | 2010-04-25 19:21:00 -0300 | [diff] [blame] | 549 | /* Keep the order of the 'case's the same as in videodev2.h! */ |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 550 | case V4L2_CID_CAMERA_CLASS: return "Camera Controls"; |
| 551 | case V4L2_CID_EXPOSURE_AUTO: return "Auto Exposure"; |
| 552 | case V4L2_CID_EXPOSURE_ABSOLUTE: return "Exposure Time, Absolute"; |
| 553 | case V4L2_CID_EXPOSURE_AUTO_PRIORITY: return "Exposure, Dynamic Framerate"; |
| 554 | case V4L2_CID_PAN_RELATIVE: return "Pan, Relative"; |
| 555 | case V4L2_CID_TILT_RELATIVE: return "Tilt, Relative"; |
| 556 | case V4L2_CID_PAN_RESET: return "Pan, Reset"; |
| 557 | case V4L2_CID_TILT_RESET: return "Tilt, Reset"; |
| 558 | case V4L2_CID_PAN_ABSOLUTE: return "Pan, Absolute"; |
| 559 | case V4L2_CID_TILT_ABSOLUTE: return "Tilt, Absolute"; |
| 560 | case V4L2_CID_FOCUS_ABSOLUTE: return "Focus, Absolute"; |
| 561 | case V4L2_CID_FOCUS_RELATIVE: return "Focus, Relative"; |
| 562 | case V4L2_CID_FOCUS_AUTO: return "Focus, Automatic"; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 563 | case V4L2_CID_ZOOM_ABSOLUTE: return "Zoom, Absolute"; |
| 564 | case V4L2_CID_ZOOM_RELATIVE: return "Zoom, Relative"; |
| 565 | case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous"; |
| 566 | case V4L2_CID_PRIVACY: return "Privacy"; |
Hans Verkuil | 6c8d611 | 2010-04-25 19:21:00 -0300 | [diff] [blame] | 567 | case V4L2_CID_IRIS_ABSOLUTE: return "Iris, Absolute"; |
| 568 | case V4L2_CID_IRIS_RELATIVE: return "Iris, Relative"; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 569 | |
| 570 | /* FM Radio Modulator control */ |
Hans Verkuil | 6c8d611 | 2010-04-25 19:21:00 -0300 | [diff] [blame] | 571 | /* Keep the order of the 'case's the same as in videodev2.h! */ |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 572 | case V4L2_CID_FM_TX_CLASS: return "FM Radio Modulator Controls"; |
| 573 | case V4L2_CID_RDS_TX_DEVIATION: return "RDS Signal Deviation"; |
| 574 | case V4L2_CID_RDS_TX_PI: return "RDS Program ID"; |
| 575 | case V4L2_CID_RDS_TX_PTY: return "RDS Program Type"; |
| 576 | case V4L2_CID_RDS_TX_PS_NAME: return "RDS PS Name"; |
| 577 | case V4L2_CID_RDS_TX_RADIO_TEXT: return "RDS Radio Text"; |
| 578 | case V4L2_CID_AUDIO_LIMITER_ENABLED: return "Audio Limiter Feature Enabled"; |
| 579 | case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: return "Audio Limiter Release Time"; |
| 580 | case V4L2_CID_AUDIO_LIMITER_DEVIATION: return "Audio Limiter Deviation"; |
| 581 | case V4L2_CID_AUDIO_COMPRESSION_ENABLED: return "Audio Compression Feature Enabled"; |
| 582 | case V4L2_CID_AUDIO_COMPRESSION_GAIN: return "Audio Compression Gain"; |
| 583 | case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: return "Audio Compression Threshold"; |
| 584 | case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: return "Audio Compression Attack Time"; |
| 585 | case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: return "Audio Compression Release Time"; |
| 586 | case V4L2_CID_PILOT_TONE_ENABLED: return "Pilot Tone Feature Enabled"; |
| 587 | case V4L2_CID_PILOT_TONE_DEVIATION: return "Pilot Tone Deviation"; |
| 588 | case V4L2_CID_PILOT_TONE_FREQUENCY: return "Pilot Tone Frequency"; |
| 589 | case V4L2_CID_TUNE_PREEMPHASIS: return "Pre-emphasis settings"; |
| 590 | case V4L2_CID_TUNE_POWER_LEVEL: return "Tune Power Level"; |
| 591 | case V4L2_CID_TUNE_ANTENNA_CAPACITOR: return "Tune Antenna Capacitor"; |
| 592 | |
Sakari Ailus | 0b159ac | 2011-03-21 12:52:51 -0300 | [diff] [blame] | 593 | /* Flash controls */ |
| 594 | case V4L2_CID_FLASH_CLASS: return "Flash controls"; |
| 595 | case V4L2_CID_FLASH_LED_MODE: return "LED mode"; |
| 596 | case V4L2_CID_FLASH_STROBE_SOURCE: return "Strobe source"; |
| 597 | case V4L2_CID_FLASH_STROBE: return "Strobe"; |
| 598 | case V4L2_CID_FLASH_STROBE_STOP: return "Stop strobe"; |
| 599 | case V4L2_CID_FLASH_STROBE_STATUS: return "Strobe status"; |
| 600 | case V4L2_CID_FLASH_TIMEOUT: return "Strobe timeout"; |
| 601 | case V4L2_CID_FLASH_INTENSITY: return "Intensity, flash mode"; |
| 602 | case V4L2_CID_FLASH_TORCH_INTENSITY: return "Intensity, torch mode"; |
| 603 | case V4L2_CID_FLASH_INDICATOR_INTENSITY: return "Intensity, indicator"; |
| 604 | case V4L2_CID_FLASH_FAULT: return "Faults"; |
| 605 | case V4L2_CID_FLASH_CHARGE: return "Charge"; |
| 606 | case V4L2_CID_FLASH_READY: return "Ready to strobe"; |
| 607 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 608 | default: |
| 609 | return NULL; |
| 610 | } |
| 611 | } |
| 612 | EXPORT_SYMBOL(v4l2_ctrl_get_name); |
| 613 | |
| 614 | void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, |
| 615 | s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags) |
| 616 | { |
| 617 | *name = v4l2_ctrl_get_name(id); |
| 618 | *flags = 0; |
| 619 | |
| 620 | switch (id) { |
| 621 | case V4L2_CID_AUDIO_MUTE: |
| 622 | case V4L2_CID_AUDIO_LOUDNESS: |
| 623 | case V4L2_CID_AUTO_WHITE_BALANCE: |
| 624 | case V4L2_CID_AUTOGAIN: |
| 625 | case V4L2_CID_HFLIP: |
| 626 | case V4L2_CID_VFLIP: |
| 627 | case V4L2_CID_HUE_AUTO: |
| 628 | case V4L2_CID_CHROMA_AGC: |
| 629 | case V4L2_CID_COLOR_KILLER: |
| 630 | case V4L2_CID_MPEG_AUDIO_MUTE: |
| 631 | case V4L2_CID_MPEG_VIDEO_MUTE: |
| 632 | case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: |
| 633 | case V4L2_CID_MPEG_VIDEO_PULLDOWN: |
| 634 | case V4L2_CID_EXPOSURE_AUTO_PRIORITY: |
| 635 | case V4L2_CID_FOCUS_AUTO: |
| 636 | case V4L2_CID_PRIVACY: |
| 637 | case V4L2_CID_AUDIO_LIMITER_ENABLED: |
| 638 | case V4L2_CID_AUDIO_COMPRESSION_ENABLED: |
| 639 | case V4L2_CID_PILOT_TONE_ENABLED: |
Jean-François Moine | 008d35f | 2010-09-13 07:04:49 -0300 | [diff] [blame] | 640 | case V4L2_CID_ILLUMINATORS_1: |
| 641 | case V4L2_CID_ILLUMINATORS_2: |
Sakari Ailus | 0b159ac | 2011-03-21 12:52:51 -0300 | [diff] [blame] | 642 | case V4L2_CID_FLASH_STROBE_STATUS: |
| 643 | case V4L2_CID_FLASH_CHARGE: |
| 644 | case V4L2_CID_FLASH_READY: |
Kamil Debski | 064f509 | 2011-06-14 10:46:22 -0300 | [diff] [blame] | 645 | case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER: |
| 646 | case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE: |
| 647 | case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE: |
| 648 | case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE: |
| 649 | case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM: |
| 650 | case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE: |
| 651 | case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL: |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 652 | *type = V4L2_CTRL_TYPE_BOOLEAN; |
| 653 | *min = 0; |
| 654 | *max = *step = 1; |
| 655 | break; |
| 656 | case V4L2_CID_PAN_RESET: |
| 657 | case V4L2_CID_TILT_RESET: |
Sakari Ailus | 0b159ac | 2011-03-21 12:52:51 -0300 | [diff] [blame] | 658 | case V4L2_CID_FLASH_STROBE: |
| 659 | case V4L2_CID_FLASH_STROBE_STOP: |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 660 | *type = V4L2_CTRL_TYPE_BUTTON; |
| 661 | *flags |= V4L2_CTRL_FLAG_WRITE_ONLY; |
| 662 | *min = *max = *step = *def = 0; |
| 663 | break; |
| 664 | case V4L2_CID_POWER_LINE_FREQUENCY: |
| 665 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: |
| 666 | case V4L2_CID_MPEG_AUDIO_ENCODING: |
| 667 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: |
| 668 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: |
| 669 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: |
| 670 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: |
| 671 | case V4L2_CID_MPEG_AUDIO_MODE: |
| 672 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: |
| 673 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: |
| 674 | case V4L2_CID_MPEG_AUDIO_CRC: |
| 675 | case V4L2_CID_MPEG_VIDEO_ENCODING: |
| 676 | case V4L2_CID_MPEG_VIDEO_ASPECT: |
| 677 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: |
| 678 | case V4L2_CID_MPEG_STREAM_TYPE: |
| 679 | case V4L2_CID_MPEG_STREAM_VBI_FMT: |
| 680 | case V4L2_CID_EXPOSURE_AUTO: |
| 681 | case V4L2_CID_COLORFX: |
| 682 | case V4L2_CID_TUNE_PREEMPHASIS: |
Sakari Ailus | 0b159ac | 2011-03-21 12:52:51 -0300 | [diff] [blame] | 683 | case V4L2_CID_FLASH_LED_MODE: |
| 684 | case V4L2_CID_FLASH_STROBE_SOURCE: |
Kamil Debski | 064f509 | 2011-06-14 10:46:22 -0300 | [diff] [blame] | 685 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: |
| 686 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: |
| 687 | case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: |
| 688 | case V4L2_CID_MPEG_VIDEO_H264_LEVEL: |
| 689 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: |
| 690 | case V4L2_CID_MPEG_VIDEO_H264_PROFILE: |
| 691 | case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC: |
| 692 | case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL: |
| 693 | case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE: |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 694 | *type = V4L2_CTRL_TYPE_MENU; |
| 695 | break; |
| 696 | case V4L2_CID_RDS_TX_PS_NAME: |
| 697 | case V4L2_CID_RDS_TX_RADIO_TEXT: |
| 698 | *type = V4L2_CTRL_TYPE_STRING; |
| 699 | break; |
| 700 | case V4L2_CID_USER_CLASS: |
| 701 | case V4L2_CID_CAMERA_CLASS: |
| 702 | case V4L2_CID_MPEG_CLASS: |
| 703 | case V4L2_CID_FM_TX_CLASS: |
Sakari Ailus | 0b159ac | 2011-03-21 12:52:51 -0300 | [diff] [blame] | 704 | case V4L2_CID_FLASH_CLASS: |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 705 | *type = V4L2_CTRL_TYPE_CTRL_CLASS; |
| 706 | /* You can neither read not write these */ |
| 707 | *flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY; |
| 708 | *min = *max = *step = *def = 0; |
| 709 | break; |
| 710 | case V4L2_CID_BG_COLOR: |
| 711 | *type = V4L2_CTRL_TYPE_INTEGER; |
| 712 | *step = 1; |
| 713 | *min = 0; |
| 714 | /* Max is calculated as RGB888 that is 2^24 */ |
| 715 | *max = 0xFFFFFF; |
| 716 | break; |
Sakari Ailus | 0b159ac | 2011-03-21 12:52:51 -0300 | [diff] [blame] | 717 | case V4L2_CID_FLASH_FAULT: |
| 718 | *type = V4L2_CTRL_TYPE_BITMASK; |
| 719 | break; |
Kamil Debski | 064f509 | 2011-06-14 10:46:22 -0300 | [diff] [blame] | 720 | case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE: |
| 721 | case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT: |
| 722 | *type = V4L2_CTRL_TYPE_INTEGER; |
| 723 | *flags |= V4L2_CTRL_FLAG_READ_ONLY; |
| 724 | break; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 725 | default: |
| 726 | *type = V4L2_CTRL_TYPE_INTEGER; |
| 727 | break; |
| 728 | } |
| 729 | switch (id) { |
| 730 | case V4L2_CID_MPEG_AUDIO_ENCODING: |
| 731 | case V4L2_CID_MPEG_AUDIO_MODE: |
| 732 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: |
| 733 | case V4L2_CID_MPEG_VIDEO_B_FRAMES: |
| 734 | case V4L2_CID_MPEG_STREAM_TYPE: |
| 735 | *flags |= V4L2_CTRL_FLAG_UPDATE; |
| 736 | break; |
| 737 | case V4L2_CID_AUDIO_VOLUME: |
| 738 | case V4L2_CID_AUDIO_BALANCE: |
| 739 | case V4L2_CID_AUDIO_BASS: |
| 740 | case V4L2_CID_AUDIO_TREBLE: |
| 741 | case V4L2_CID_BRIGHTNESS: |
| 742 | case V4L2_CID_CONTRAST: |
| 743 | case V4L2_CID_SATURATION: |
| 744 | case V4L2_CID_HUE: |
| 745 | case V4L2_CID_RED_BALANCE: |
| 746 | case V4L2_CID_BLUE_BALANCE: |
| 747 | case V4L2_CID_GAMMA: |
| 748 | case V4L2_CID_SHARPNESS: |
| 749 | case V4L2_CID_CHROMA_GAIN: |
| 750 | case V4L2_CID_RDS_TX_DEVIATION: |
| 751 | case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: |
| 752 | case V4L2_CID_AUDIO_LIMITER_DEVIATION: |
| 753 | case V4L2_CID_AUDIO_COMPRESSION_GAIN: |
| 754 | case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: |
| 755 | case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: |
| 756 | case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: |
| 757 | case V4L2_CID_PILOT_TONE_DEVIATION: |
| 758 | case V4L2_CID_PILOT_TONE_FREQUENCY: |
| 759 | case V4L2_CID_TUNE_POWER_LEVEL: |
| 760 | case V4L2_CID_TUNE_ANTENNA_CAPACITOR: |
| 761 | *flags |= V4L2_CTRL_FLAG_SLIDER; |
| 762 | break; |
| 763 | case V4L2_CID_PAN_RELATIVE: |
| 764 | case V4L2_CID_TILT_RELATIVE: |
| 765 | case V4L2_CID_FOCUS_RELATIVE: |
| 766 | case V4L2_CID_IRIS_RELATIVE: |
| 767 | case V4L2_CID_ZOOM_RELATIVE: |
| 768 | *flags |= V4L2_CTRL_FLAG_WRITE_ONLY; |
| 769 | break; |
Sakari Ailus | 0b159ac | 2011-03-21 12:52:51 -0300 | [diff] [blame] | 770 | case V4L2_CID_FLASH_STROBE_STATUS: |
| 771 | case V4L2_CID_FLASH_READY: |
| 772 | *flags |= V4L2_CTRL_FLAG_READ_ONLY; |
| 773 | break; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | EXPORT_SYMBOL(v4l2_ctrl_fill); |
| 777 | |
| 778 | /* Helper function to determine whether the control type is compatible with |
| 779 | VIDIOC_G/S_CTRL. */ |
| 780 | static bool type_is_int(const struct v4l2_ctrl *ctrl) |
| 781 | { |
| 782 | switch (ctrl->type) { |
| 783 | case V4L2_CTRL_TYPE_INTEGER64: |
| 784 | case V4L2_CTRL_TYPE_STRING: |
| 785 | /* Nope, these need v4l2_ext_control */ |
| 786 | return false; |
| 787 | default: |
| 788 | return true; |
| 789 | } |
| 790 | } |
| 791 | |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 792 | static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl, u32 changes) |
| 793 | { |
| 794 | memset(ev->reserved, 0, sizeof(ev->reserved)); |
| 795 | ev->type = V4L2_EVENT_CTRL; |
| 796 | ev->id = ctrl->id; |
| 797 | ev->u.ctrl.changes = changes; |
| 798 | ev->u.ctrl.type = ctrl->type; |
| 799 | ev->u.ctrl.flags = ctrl->flags; |
| 800 | if (ctrl->type == V4L2_CTRL_TYPE_STRING) |
| 801 | ev->u.ctrl.value64 = 0; |
| 802 | else |
| 803 | ev->u.ctrl.value64 = ctrl->cur.val64; |
| 804 | ev->u.ctrl.minimum = ctrl->minimum; |
| 805 | ev->u.ctrl.maximum = ctrl->maximum; |
| 806 | if (ctrl->type == V4L2_CTRL_TYPE_MENU) |
| 807 | ev->u.ctrl.step = 1; |
| 808 | else |
| 809 | ev->u.ctrl.step = ctrl->step; |
| 810 | ev->u.ctrl.default_value = ctrl->default_value; |
| 811 | } |
| 812 | |
| 813 | static void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes) |
| 814 | { |
| 815 | struct v4l2_event ev; |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 816 | struct v4l2_subscribed_event *sev; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 817 | |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 818 | if (list_empty(&ctrl->ev_subs)) |
Hans Verkuil | 3f66f0e | 2011-06-20 11:56:24 -0300 | [diff] [blame] | 819 | return; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 820 | fill_event(&ev, ctrl, changes); |
| 821 | |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 822 | list_for_each_entry(sev, &ctrl->ev_subs, node) |
Hans Verkuil | 60c07322 | 2011-06-29 08:56:22 -0300 | [diff] [blame] | 823 | if (sev->fh && (sev->fh != fh || |
| 824 | (sev->flags & V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK))) |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 825 | v4l2_event_queue_fh(sev->fh, &ev); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 826 | } |
| 827 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 828 | /* Helper function: copy the current control value back to the caller */ |
| 829 | static int cur_to_user(struct v4l2_ext_control *c, |
| 830 | struct v4l2_ctrl *ctrl) |
| 831 | { |
| 832 | u32 len; |
| 833 | |
| 834 | switch (ctrl->type) { |
| 835 | case V4L2_CTRL_TYPE_STRING: |
| 836 | len = strlen(ctrl->cur.string); |
| 837 | if (c->size < len + 1) { |
| 838 | c->size = len + 1; |
| 839 | return -ENOSPC; |
| 840 | } |
| 841 | return copy_to_user(c->string, ctrl->cur.string, |
| 842 | len + 1) ? -EFAULT : 0; |
| 843 | case V4L2_CTRL_TYPE_INTEGER64: |
| 844 | c->value64 = ctrl->cur.val64; |
| 845 | break; |
| 846 | default: |
| 847 | c->value = ctrl->cur.val; |
| 848 | break; |
| 849 | } |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | /* Helper function: copy the caller-provider value as the new control value */ |
| 854 | static int user_to_new(struct v4l2_ext_control *c, |
| 855 | struct v4l2_ctrl *ctrl) |
| 856 | { |
| 857 | int ret; |
| 858 | u32 size; |
| 859 | |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 860 | ctrl->is_new = 1; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 861 | switch (ctrl->type) { |
| 862 | case V4L2_CTRL_TYPE_INTEGER64: |
| 863 | ctrl->val64 = c->value64; |
| 864 | break; |
| 865 | case V4L2_CTRL_TYPE_STRING: |
| 866 | size = c->size; |
| 867 | if (size == 0) |
| 868 | return -ERANGE; |
| 869 | if (size > ctrl->maximum + 1) |
| 870 | size = ctrl->maximum + 1; |
| 871 | ret = copy_from_user(ctrl->string, c->string, size); |
| 872 | if (!ret) { |
| 873 | char last = ctrl->string[size - 1]; |
| 874 | |
| 875 | ctrl->string[size - 1] = 0; |
| 876 | /* If the string was longer than ctrl->maximum, |
| 877 | then return an error. */ |
| 878 | if (strlen(ctrl->string) == ctrl->maximum && last) |
| 879 | return -ERANGE; |
| 880 | } |
| 881 | return ret ? -EFAULT : 0; |
| 882 | default: |
| 883 | ctrl->val = c->value; |
| 884 | break; |
| 885 | } |
| 886 | return 0; |
| 887 | } |
| 888 | |
| 889 | /* Helper function: copy the new control value back to the caller */ |
| 890 | static int new_to_user(struct v4l2_ext_control *c, |
| 891 | struct v4l2_ctrl *ctrl) |
| 892 | { |
| 893 | u32 len; |
| 894 | |
| 895 | switch (ctrl->type) { |
| 896 | case V4L2_CTRL_TYPE_STRING: |
| 897 | len = strlen(ctrl->string); |
| 898 | if (c->size < len + 1) { |
| 899 | c->size = ctrl->maximum + 1; |
| 900 | return -ENOSPC; |
| 901 | } |
| 902 | return copy_to_user(c->string, ctrl->string, |
| 903 | len + 1) ? -EFAULT : 0; |
| 904 | case V4L2_CTRL_TYPE_INTEGER64: |
| 905 | c->value64 = ctrl->val64; |
| 906 | break; |
| 907 | default: |
| 908 | c->value = ctrl->val; |
| 909 | break; |
| 910 | } |
| 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | /* Copy the new value to the current value. */ |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 915 | static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, |
| 916 | bool update_inactive) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 917 | { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 918 | bool changed = false; |
| 919 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 920 | if (ctrl == NULL) |
| 921 | return; |
| 922 | switch (ctrl->type) { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 923 | case V4L2_CTRL_TYPE_BUTTON: |
| 924 | changed = true; |
| 925 | break; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 926 | case V4L2_CTRL_TYPE_STRING: |
| 927 | /* strings are always 0-terminated */ |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 928 | changed = strcmp(ctrl->string, ctrl->cur.string); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 929 | strcpy(ctrl->cur.string, ctrl->string); |
| 930 | break; |
| 931 | case V4L2_CTRL_TYPE_INTEGER64: |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 932 | changed = ctrl->val64 != ctrl->cur.val64; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 933 | ctrl->cur.val64 = ctrl->val64; |
| 934 | break; |
| 935 | default: |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 936 | changed = ctrl->val != ctrl->cur.val; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 937 | ctrl->cur.val = ctrl->val; |
| 938 | break; |
| 939 | } |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 940 | if (update_inactive) { |
| 941 | ctrl->flags &= ~V4L2_CTRL_FLAG_INACTIVE; |
| 942 | if (!is_cur_manual(ctrl->cluster[0])) |
| 943 | ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; |
| 944 | } |
Hans Verkuil | 639884a | 2011-07-05 07:09:26 -0300 | [diff] [blame] | 945 | if (changed || update_inactive) { |
| 946 | /* If a control was changed that was not one of the controls |
| 947 | modified by the application, then send the event to all. */ |
| 948 | if (!ctrl->is_new) |
| 949 | fh = NULL; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 950 | send_event(fh, ctrl, |
| 951 | (changed ? V4L2_EVENT_CTRL_CH_VALUE : 0) | |
| 952 | (update_inactive ? V4L2_EVENT_CTRL_CH_FLAGS : 0)); |
Hans Verkuil | 639884a | 2011-07-05 07:09:26 -0300 | [diff] [blame] | 953 | } |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | /* Copy the current value to the new value */ |
| 957 | static void cur_to_new(struct v4l2_ctrl *ctrl) |
| 958 | { |
| 959 | if (ctrl == NULL) |
| 960 | return; |
| 961 | switch (ctrl->type) { |
| 962 | case V4L2_CTRL_TYPE_STRING: |
| 963 | /* strings are always 0-terminated */ |
| 964 | strcpy(ctrl->string, ctrl->cur.string); |
| 965 | break; |
| 966 | case V4L2_CTRL_TYPE_INTEGER64: |
| 967 | ctrl->val64 = ctrl->cur.val64; |
| 968 | break; |
| 969 | default: |
| 970 | ctrl->val = ctrl->cur.val; |
| 971 | break; |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | /* Return non-zero if one or more of the controls in the cluster has a new |
| 976 | value that differs from the current value. */ |
| 977 | static int cluster_changed(struct v4l2_ctrl *master) |
| 978 | { |
| 979 | int diff = 0; |
| 980 | int i; |
| 981 | |
| 982 | for (i = 0; !diff && i < master->ncontrols; i++) { |
| 983 | struct v4l2_ctrl *ctrl = master->cluster[i]; |
| 984 | |
| 985 | if (ctrl == NULL) |
| 986 | continue; |
| 987 | switch (ctrl->type) { |
| 988 | case V4L2_CTRL_TYPE_BUTTON: |
| 989 | /* Button controls are always 'different' */ |
| 990 | return 1; |
| 991 | case V4L2_CTRL_TYPE_STRING: |
| 992 | /* strings are always 0-terminated */ |
| 993 | diff = strcmp(ctrl->string, ctrl->cur.string); |
| 994 | break; |
| 995 | case V4L2_CTRL_TYPE_INTEGER64: |
| 996 | diff = ctrl->val64 != ctrl->cur.val64; |
| 997 | break; |
| 998 | default: |
| 999 | diff = ctrl->val != ctrl->cur.val; |
| 1000 | break; |
| 1001 | } |
| 1002 | } |
| 1003 | return diff; |
| 1004 | } |
| 1005 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1006 | /* Validate integer-type control */ |
| 1007 | static int validate_new_int(const struct v4l2_ctrl *ctrl, s32 *pval) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1008 | { |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1009 | s32 val = *pval; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1010 | u32 offset; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1011 | |
| 1012 | switch (ctrl->type) { |
| 1013 | case V4L2_CTRL_TYPE_INTEGER: |
| 1014 | /* Round towards the closest legal value */ |
| 1015 | val += ctrl->step / 2; |
| 1016 | if (val < ctrl->minimum) |
| 1017 | val = ctrl->minimum; |
| 1018 | if (val > ctrl->maximum) |
| 1019 | val = ctrl->maximum; |
| 1020 | offset = val - ctrl->minimum; |
| 1021 | offset = ctrl->step * (offset / ctrl->step); |
| 1022 | val = ctrl->minimum + offset; |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1023 | *pval = val; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1024 | return 0; |
| 1025 | |
| 1026 | case V4L2_CTRL_TYPE_BOOLEAN: |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1027 | *pval = !!val; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1028 | return 0; |
| 1029 | |
| 1030 | case V4L2_CTRL_TYPE_MENU: |
| 1031 | if (val < ctrl->minimum || val > ctrl->maximum) |
| 1032 | return -ERANGE; |
| 1033 | if (ctrl->qmenu[val][0] == '\0' || |
| 1034 | (ctrl->menu_skip_mask & (1 << val))) |
| 1035 | return -EINVAL; |
| 1036 | return 0; |
| 1037 | |
Hans Verkuil | fa4d709 | 2011-05-23 04:07:05 -0300 | [diff] [blame] | 1038 | case V4L2_CTRL_TYPE_BITMASK: |
| 1039 | *pval &= ctrl->maximum; |
| 1040 | return 0; |
| 1041 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1042 | case V4L2_CTRL_TYPE_BUTTON: |
| 1043 | case V4L2_CTRL_TYPE_CTRL_CLASS: |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1044 | *pval = 0; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1045 | return 0; |
| 1046 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1047 | default: |
| 1048 | return -EINVAL; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | /* Validate a new control */ |
| 1053 | static int validate_new(const struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c) |
| 1054 | { |
| 1055 | char *s = c->string; |
| 1056 | size_t len; |
| 1057 | |
| 1058 | switch (ctrl->type) { |
| 1059 | case V4L2_CTRL_TYPE_INTEGER: |
| 1060 | case V4L2_CTRL_TYPE_BOOLEAN: |
| 1061 | case V4L2_CTRL_TYPE_MENU: |
Hans Verkuil | fa4d709 | 2011-05-23 04:07:05 -0300 | [diff] [blame] | 1062 | case V4L2_CTRL_TYPE_BITMASK: |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1063 | case V4L2_CTRL_TYPE_BUTTON: |
| 1064 | case V4L2_CTRL_TYPE_CTRL_CLASS: |
| 1065 | return validate_new_int(ctrl, &c->value); |
| 1066 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1067 | case V4L2_CTRL_TYPE_INTEGER64: |
| 1068 | return 0; |
| 1069 | |
| 1070 | case V4L2_CTRL_TYPE_STRING: |
| 1071 | len = strlen(s); |
| 1072 | if (len < ctrl->minimum) |
| 1073 | return -ERANGE; |
| 1074 | if ((len - ctrl->minimum) % ctrl->step) |
| 1075 | return -ERANGE; |
| 1076 | return 0; |
| 1077 | |
| 1078 | default: |
| 1079 | return -EINVAL; |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | static inline u32 node2id(struct list_head *node) |
| 1084 | { |
| 1085 | return list_entry(node, struct v4l2_ctrl_ref, node)->ctrl->id; |
| 1086 | } |
| 1087 | |
| 1088 | /* Set the handler's error code if it wasn't set earlier already */ |
| 1089 | static inline int handler_set_err(struct v4l2_ctrl_handler *hdl, int err) |
| 1090 | { |
| 1091 | if (hdl->error == 0) |
| 1092 | hdl->error = err; |
| 1093 | return err; |
| 1094 | } |
| 1095 | |
| 1096 | /* Initialize the handler */ |
| 1097 | int v4l2_ctrl_handler_init(struct v4l2_ctrl_handler *hdl, |
| 1098 | unsigned nr_of_controls_hint) |
| 1099 | { |
| 1100 | mutex_init(&hdl->lock); |
| 1101 | INIT_LIST_HEAD(&hdl->ctrls); |
| 1102 | INIT_LIST_HEAD(&hdl->ctrl_refs); |
| 1103 | hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8; |
| 1104 | hdl->buckets = kzalloc(sizeof(hdl->buckets[0]) * hdl->nr_of_buckets, |
| 1105 | GFP_KERNEL); |
| 1106 | hdl->error = hdl->buckets ? 0 : -ENOMEM; |
| 1107 | return hdl->error; |
| 1108 | } |
| 1109 | EXPORT_SYMBOL(v4l2_ctrl_handler_init); |
| 1110 | |
| 1111 | /* Free all controls and control refs */ |
| 1112 | void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl) |
| 1113 | { |
| 1114 | struct v4l2_ctrl_ref *ref, *next_ref; |
| 1115 | struct v4l2_ctrl *ctrl, *next_ctrl; |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 1116 | struct v4l2_subscribed_event *sev, *next_sev; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1117 | |
| 1118 | if (hdl == NULL || hdl->buckets == NULL) |
| 1119 | return; |
| 1120 | |
| 1121 | mutex_lock(&hdl->lock); |
| 1122 | /* Free all nodes */ |
| 1123 | list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) { |
| 1124 | list_del(&ref->node); |
| 1125 | kfree(ref); |
| 1126 | } |
| 1127 | /* Free all controls owned by the handler */ |
| 1128 | list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) { |
| 1129 | list_del(&ctrl->node); |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 1130 | list_for_each_entry_safe(sev, next_sev, &ctrl->ev_subs, node) |
| 1131 | list_del(&sev->node); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1132 | kfree(ctrl); |
| 1133 | } |
| 1134 | kfree(hdl->buckets); |
| 1135 | hdl->buckets = NULL; |
| 1136 | hdl->cached = NULL; |
| 1137 | hdl->error = 0; |
| 1138 | mutex_unlock(&hdl->lock); |
| 1139 | } |
| 1140 | EXPORT_SYMBOL(v4l2_ctrl_handler_free); |
| 1141 | |
| 1142 | /* For backwards compatibility: V4L2_CID_PRIVATE_BASE should no longer |
| 1143 | be used except in G_CTRL, S_CTRL, QUERYCTRL and QUERYMENU when dealing |
| 1144 | with applications that do not use the NEXT_CTRL flag. |
| 1145 | |
| 1146 | We just find the n-th private user control. It's O(N), but that should not |
| 1147 | be an issue in this particular case. */ |
| 1148 | static struct v4l2_ctrl_ref *find_private_ref( |
| 1149 | struct v4l2_ctrl_handler *hdl, u32 id) |
| 1150 | { |
| 1151 | struct v4l2_ctrl_ref *ref; |
| 1152 | |
| 1153 | id -= V4L2_CID_PRIVATE_BASE; |
| 1154 | list_for_each_entry(ref, &hdl->ctrl_refs, node) { |
| 1155 | /* Search for private user controls that are compatible with |
| 1156 | VIDIOC_G/S_CTRL. */ |
| 1157 | if (V4L2_CTRL_ID2CLASS(ref->ctrl->id) == V4L2_CTRL_CLASS_USER && |
| 1158 | V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) { |
| 1159 | if (!type_is_int(ref->ctrl)) |
| 1160 | continue; |
| 1161 | if (id == 0) |
| 1162 | return ref; |
| 1163 | id--; |
| 1164 | } |
| 1165 | } |
| 1166 | return NULL; |
| 1167 | } |
| 1168 | |
| 1169 | /* Find a control with the given ID. */ |
| 1170 | static struct v4l2_ctrl_ref *find_ref(struct v4l2_ctrl_handler *hdl, u32 id) |
| 1171 | { |
| 1172 | struct v4l2_ctrl_ref *ref; |
| 1173 | int bucket; |
| 1174 | |
| 1175 | id &= V4L2_CTRL_ID_MASK; |
| 1176 | |
| 1177 | /* Old-style private controls need special handling */ |
| 1178 | if (id >= V4L2_CID_PRIVATE_BASE) |
| 1179 | return find_private_ref(hdl, id); |
| 1180 | bucket = id % hdl->nr_of_buckets; |
| 1181 | |
| 1182 | /* Simple optimization: cache the last control found */ |
| 1183 | if (hdl->cached && hdl->cached->ctrl->id == id) |
| 1184 | return hdl->cached; |
| 1185 | |
| 1186 | /* Not in cache, search the hash */ |
| 1187 | ref = hdl->buckets ? hdl->buckets[bucket] : NULL; |
| 1188 | while (ref && ref->ctrl->id != id) |
| 1189 | ref = ref->next; |
| 1190 | |
| 1191 | if (ref) |
| 1192 | hdl->cached = ref; /* cache it! */ |
| 1193 | return ref; |
| 1194 | } |
| 1195 | |
| 1196 | /* Find a control with the given ID. Take the handler's lock first. */ |
| 1197 | static struct v4l2_ctrl_ref *find_ref_lock( |
| 1198 | struct v4l2_ctrl_handler *hdl, u32 id) |
| 1199 | { |
| 1200 | struct v4l2_ctrl_ref *ref = NULL; |
| 1201 | |
| 1202 | if (hdl) { |
| 1203 | mutex_lock(&hdl->lock); |
| 1204 | ref = find_ref(hdl, id); |
| 1205 | mutex_unlock(&hdl->lock); |
| 1206 | } |
| 1207 | return ref; |
| 1208 | } |
| 1209 | |
| 1210 | /* Find a control with the given ID. */ |
| 1211 | struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id) |
| 1212 | { |
| 1213 | struct v4l2_ctrl_ref *ref = find_ref_lock(hdl, id); |
| 1214 | |
| 1215 | return ref ? ref->ctrl : NULL; |
| 1216 | } |
| 1217 | EXPORT_SYMBOL(v4l2_ctrl_find); |
| 1218 | |
| 1219 | /* Allocate a new v4l2_ctrl_ref and hook it into the handler. */ |
| 1220 | static int handler_new_ref(struct v4l2_ctrl_handler *hdl, |
| 1221 | struct v4l2_ctrl *ctrl) |
| 1222 | { |
| 1223 | struct v4l2_ctrl_ref *ref; |
| 1224 | struct v4l2_ctrl_ref *new_ref; |
| 1225 | u32 id = ctrl->id; |
| 1226 | u32 class_ctrl = V4L2_CTRL_ID2CLASS(id) | 1; |
| 1227 | int bucket = id % hdl->nr_of_buckets; /* which bucket to use */ |
| 1228 | |
| 1229 | /* Automatically add the control class if it is not yet present. */ |
| 1230 | if (id != class_ctrl && find_ref_lock(hdl, class_ctrl) == NULL) |
| 1231 | if (!v4l2_ctrl_new_std(hdl, NULL, class_ctrl, 0, 0, 0, 0)) |
| 1232 | return hdl->error; |
| 1233 | |
| 1234 | if (hdl->error) |
| 1235 | return hdl->error; |
| 1236 | |
| 1237 | new_ref = kzalloc(sizeof(*new_ref), GFP_KERNEL); |
| 1238 | if (!new_ref) |
| 1239 | return handler_set_err(hdl, -ENOMEM); |
| 1240 | new_ref->ctrl = ctrl; |
| 1241 | if (ctrl->handler == hdl) { |
| 1242 | /* By default each control starts in a cluster of its own. |
| 1243 | new_ref->ctrl is basically a cluster array with one |
| 1244 | element, so that's perfect to use as the cluster pointer. |
| 1245 | But only do this for the handler that owns the control. */ |
| 1246 | ctrl->cluster = &new_ref->ctrl; |
| 1247 | ctrl->ncontrols = 1; |
| 1248 | } |
| 1249 | |
| 1250 | INIT_LIST_HEAD(&new_ref->node); |
| 1251 | |
| 1252 | mutex_lock(&hdl->lock); |
| 1253 | |
| 1254 | /* Add immediately at the end of the list if the list is empty, or if |
| 1255 | the last element in the list has a lower ID. |
| 1256 | This ensures that when elements are added in ascending order the |
| 1257 | insertion is an O(1) operation. */ |
| 1258 | if (list_empty(&hdl->ctrl_refs) || id > node2id(hdl->ctrl_refs.prev)) { |
| 1259 | list_add_tail(&new_ref->node, &hdl->ctrl_refs); |
| 1260 | goto insert_in_hash; |
| 1261 | } |
| 1262 | |
| 1263 | /* Find insert position in sorted list */ |
| 1264 | list_for_each_entry(ref, &hdl->ctrl_refs, node) { |
| 1265 | if (ref->ctrl->id < id) |
| 1266 | continue; |
| 1267 | /* Don't add duplicates */ |
| 1268 | if (ref->ctrl->id == id) { |
| 1269 | kfree(new_ref); |
| 1270 | goto unlock; |
| 1271 | } |
| 1272 | list_add(&new_ref->node, ref->node.prev); |
| 1273 | break; |
| 1274 | } |
| 1275 | |
| 1276 | insert_in_hash: |
| 1277 | /* Insert the control node in the hash */ |
| 1278 | new_ref->next = hdl->buckets[bucket]; |
| 1279 | hdl->buckets[bucket] = new_ref; |
| 1280 | |
| 1281 | unlock: |
| 1282 | mutex_unlock(&hdl->lock); |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
| 1286 | /* Add a new control */ |
| 1287 | static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, |
| 1288 | const struct v4l2_ctrl_ops *ops, |
| 1289 | u32 id, const char *name, enum v4l2_ctrl_type type, |
| 1290 | s32 min, s32 max, u32 step, s32 def, |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 1291 | u32 flags, const char * const *qmenu, void *priv) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1292 | { |
| 1293 | struct v4l2_ctrl *ctrl; |
| 1294 | unsigned sz_extra = 0; |
| 1295 | |
| 1296 | if (hdl->error) |
| 1297 | return NULL; |
| 1298 | |
| 1299 | /* Sanity checks */ |
| 1300 | if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE || |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1301 | (type == V4L2_CTRL_TYPE_INTEGER && step == 0) || |
Hans Verkuil | fa4d709 | 2011-05-23 04:07:05 -0300 | [diff] [blame] | 1302 | (type == V4L2_CTRL_TYPE_BITMASK && max == 0) || |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1303 | (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) || |
| 1304 | (type == V4L2_CTRL_TYPE_STRING && max == 0)) { |
| 1305 | handler_set_err(hdl, -ERANGE); |
| 1306 | return NULL; |
| 1307 | } |
Hans Verkuil | fa4d709 | 2011-05-23 04:07:05 -0300 | [diff] [blame] | 1308 | if (type != V4L2_CTRL_TYPE_BITMASK && max < min) { |
| 1309 | handler_set_err(hdl, -ERANGE); |
| 1310 | return NULL; |
| 1311 | } |
Hans Verkuil | 02ac048 | 2010-12-29 14:27:05 -0300 | [diff] [blame] | 1312 | if ((type == V4L2_CTRL_TYPE_INTEGER || |
| 1313 | type == V4L2_CTRL_TYPE_MENU || |
| 1314 | type == V4L2_CTRL_TYPE_BOOLEAN) && |
| 1315 | (def < min || def > max)) { |
| 1316 | handler_set_err(hdl, -ERANGE); |
| 1317 | return NULL; |
| 1318 | } |
Hans Verkuil | fa4d709 | 2011-05-23 04:07:05 -0300 | [diff] [blame] | 1319 | if (type == V4L2_CTRL_TYPE_BITMASK && ((def & ~max) || min || step)) { |
| 1320 | handler_set_err(hdl, -ERANGE); |
| 1321 | return NULL; |
| 1322 | } |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1323 | |
| 1324 | if (type == V4L2_CTRL_TYPE_BUTTON) |
| 1325 | flags |= V4L2_CTRL_FLAG_WRITE_ONLY; |
| 1326 | else if (type == V4L2_CTRL_TYPE_CTRL_CLASS) |
| 1327 | flags |= V4L2_CTRL_FLAG_READ_ONLY; |
| 1328 | else if (type == V4L2_CTRL_TYPE_STRING) |
| 1329 | sz_extra += 2 * (max + 1); |
| 1330 | |
| 1331 | ctrl = kzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL); |
| 1332 | if (ctrl == NULL) { |
| 1333 | handler_set_err(hdl, -ENOMEM); |
| 1334 | return NULL; |
| 1335 | } |
| 1336 | |
| 1337 | INIT_LIST_HEAD(&ctrl->node); |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 1338 | INIT_LIST_HEAD(&ctrl->ev_subs); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1339 | ctrl->handler = hdl; |
| 1340 | ctrl->ops = ops; |
| 1341 | ctrl->id = id; |
| 1342 | ctrl->name = name; |
| 1343 | ctrl->type = type; |
| 1344 | ctrl->flags = flags; |
| 1345 | ctrl->minimum = min; |
| 1346 | ctrl->maximum = max; |
| 1347 | ctrl->step = step; |
| 1348 | ctrl->qmenu = qmenu; |
| 1349 | ctrl->priv = priv; |
| 1350 | ctrl->cur.val = ctrl->val = ctrl->default_value = def; |
| 1351 | |
| 1352 | if (ctrl->type == V4L2_CTRL_TYPE_STRING) { |
| 1353 | ctrl->cur.string = (char *)&ctrl[1] + sz_extra - (max + 1); |
| 1354 | ctrl->string = (char *)&ctrl[1] + sz_extra - 2 * (max + 1); |
| 1355 | if (ctrl->minimum) |
| 1356 | memset(ctrl->cur.string, ' ', ctrl->minimum); |
| 1357 | } |
| 1358 | if (handler_new_ref(hdl, ctrl)) { |
| 1359 | kfree(ctrl); |
| 1360 | return NULL; |
| 1361 | } |
| 1362 | mutex_lock(&hdl->lock); |
| 1363 | list_add_tail(&ctrl->node, &hdl->ctrls); |
| 1364 | mutex_unlock(&hdl->lock); |
| 1365 | return ctrl; |
| 1366 | } |
| 1367 | |
| 1368 | struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, |
| 1369 | const struct v4l2_ctrl_config *cfg, void *priv) |
| 1370 | { |
| 1371 | bool is_menu; |
| 1372 | struct v4l2_ctrl *ctrl; |
| 1373 | const char *name = cfg->name; |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 1374 | const char * const *qmenu = cfg->qmenu; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1375 | enum v4l2_ctrl_type type = cfg->type; |
| 1376 | u32 flags = cfg->flags; |
| 1377 | s32 min = cfg->min; |
| 1378 | s32 max = cfg->max; |
| 1379 | u32 step = cfg->step; |
| 1380 | s32 def = cfg->def; |
| 1381 | |
| 1382 | if (name == NULL) |
| 1383 | v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step, |
| 1384 | &def, &flags); |
| 1385 | |
| 1386 | is_menu = (cfg->type == V4L2_CTRL_TYPE_MENU); |
| 1387 | if (is_menu) |
| 1388 | WARN_ON(step); |
| 1389 | else |
| 1390 | WARN_ON(cfg->menu_skip_mask); |
| 1391 | if (is_menu && qmenu == NULL) |
| 1392 | qmenu = v4l2_ctrl_get_menu(cfg->id); |
| 1393 | |
| 1394 | ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->id, name, |
| 1395 | type, min, max, |
| 1396 | is_menu ? cfg->menu_skip_mask : step, |
| 1397 | def, flags, qmenu, priv); |
| 1398 | if (ctrl) { |
| 1399 | ctrl->is_private = cfg->is_private; |
| 1400 | ctrl->is_volatile = cfg->is_volatile; |
| 1401 | } |
| 1402 | return ctrl; |
| 1403 | } |
| 1404 | EXPORT_SYMBOL(v4l2_ctrl_new_custom); |
| 1405 | |
| 1406 | /* Helper function for standard non-menu controls */ |
| 1407 | struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, |
| 1408 | const struct v4l2_ctrl_ops *ops, |
| 1409 | u32 id, s32 min, s32 max, u32 step, s32 def) |
| 1410 | { |
| 1411 | const char *name; |
| 1412 | enum v4l2_ctrl_type type; |
| 1413 | u32 flags; |
| 1414 | |
| 1415 | v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags); |
| 1416 | if (type == V4L2_CTRL_TYPE_MENU) { |
| 1417 | handler_set_err(hdl, -EINVAL); |
| 1418 | return NULL; |
| 1419 | } |
| 1420 | return v4l2_ctrl_new(hdl, ops, id, name, type, |
| 1421 | min, max, step, def, flags, NULL, NULL); |
| 1422 | } |
| 1423 | EXPORT_SYMBOL(v4l2_ctrl_new_std); |
| 1424 | |
| 1425 | /* Helper function for standard menu controls */ |
| 1426 | struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, |
| 1427 | const struct v4l2_ctrl_ops *ops, |
| 1428 | u32 id, s32 max, s32 mask, s32 def) |
| 1429 | { |
Hans Verkuil | 513521e | 2010-12-29 14:25:52 -0300 | [diff] [blame] | 1430 | const char * const *qmenu = v4l2_ctrl_get_menu(id); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1431 | const char *name; |
| 1432 | enum v4l2_ctrl_type type; |
| 1433 | s32 min; |
| 1434 | s32 step; |
| 1435 | u32 flags; |
| 1436 | |
| 1437 | v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags); |
| 1438 | if (type != V4L2_CTRL_TYPE_MENU) { |
| 1439 | handler_set_err(hdl, -EINVAL); |
| 1440 | return NULL; |
| 1441 | } |
| 1442 | return v4l2_ctrl_new(hdl, ops, id, name, type, |
| 1443 | 0, max, mask, def, flags, qmenu, NULL); |
| 1444 | } |
| 1445 | EXPORT_SYMBOL(v4l2_ctrl_new_std_menu); |
| 1446 | |
| 1447 | /* Add a control from another handler to this handler */ |
| 1448 | struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, |
| 1449 | struct v4l2_ctrl *ctrl) |
| 1450 | { |
| 1451 | if (hdl == NULL || hdl->error) |
| 1452 | return NULL; |
| 1453 | if (ctrl == NULL) { |
| 1454 | handler_set_err(hdl, -EINVAL); |
| 1455 | return NULL; |
| 1456 | } |
| 1457 | if (ctrl->handler == hdl) |
| 1458 | return ctrl; |
| 1459 | return handler_new_ref(hdl, ctrl) ? NULL : ctrl; |
| 1460 | } |
| 1461 | EXPORT_SYMBOL(v4l2_ctrl_add_ctrl); |
| 1462 | |
| 1463 | /* Add the controls from another handler to our own. */ |
| 1464 | int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, |
| 1465 | struct v4l2_ctrl_handler *add) |
| 1466 | { |
| 1467 | struct v4l2_ctrl *ctrl; |
| 1468 | int ret = 0; |
| 1469 | |
| 1470 | /* Do nothing if either handler is NULL or if they are the same */ |
| 1471 | if (!hdl || !add || hdl == add) |
| 1472 | return 0; |
| 1473 | if (hdl->error) |
| 1474 | return hdl->error; |
| 1475 | mutex_lock(&add->lock); |
| 1476 | list_for_each_entry(ctrl, &add->ctrls, node) { |
| 1477 | /* Skip handler-private controls. */ |
| 1478 | if (ctrl->is_private) |
| 1479 | continue; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 1480 | /* And control classes */ |
| 1481 | if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) |
| 1482 | continue; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1483 | ret = handler_new_ref(hdl, ctrl); |
| 1484 | if (ret) |
| 1485 | break; |
| 1486 | } |
| 1487 | mutex_unlock(&add->lock); |
| 1488 | return ret; |
| 1489 | } |
| 1490 | EXPORT_SYMBOL(v4l2_ctrl_add_handler); |
| 1491 | |
| 1492 | /* Cluster controls */ |
| 1493 | void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls) |
| 1494 | { |
| 1495 | int i; |
| 1496 | |
| 1497 | /* The first control is the master control and it must not be NULL */ |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 1498 | BUG_ON(ncontrols == 0 || controls[0] == NULL); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1499 | |
| 1500 | for (i = 0; i < ncontrols; i++) { |
| 1501 | if (controls[i]) { |
| 1502 | controls[i]->cluster = controls; |
| 1503 | controls[i]->ncontrols = ncontrols; |
| 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | EXPORT_SYMBOL(v4l2_ctrl_cluster); |
| 1508 | |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 1509 | void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls, |
| 1510 | u8 manual_val, bool set_volatile) |
| 1511 | { |
| 1512 | struct v4l2_ctrl *master = controls[0]; |
| 1513 | u32 flag; |
| 1514 | int i; |
| 1515 | |
| 1516 | v4l2_ctrl_cluster(ncontrols, controls); |
| 1517 | WARN_ON(ncontrols <= 1); |
Hans Verkuil | 82a7c04 | 2011-06-28 10:43:13 -0300 | [diff] [blame] | 1518 | WARN_ON(manual_val < master->minimum || manual_val > master->maximum); |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 1519 | master->is_auto = true; |
| 1520 | master->manual_mode_value = manual_val; |
| 1521 | master->flags |= V4L2_CTRL_FLAG_UPDATE; |
| 1522 | flag = is_cur_manual(master) ? 0 : V4L2_CTRL_FLAG_INACTIVE; |
| 1523 | |
| 1524 | for (i = 1; i < ncontrols; i++) |
| 1525 | if (controls[i]) { |
| 1526 | controls[i]->is_volatile = set_volatile; |
| 1527 | controls[i]->flags |= flag; |
| 1528 | } |
| 1529 | } |
| 1530 | EXPORT_SYMBOL(v4l2_ctrl_auto_cluster); |
| 1531 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1532 | /* Activate/deactivate a control. */ |
| 1533 | void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active) |
| 1534 | { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 1535 | /* invert since the actual flag is called 'inactive' */ |
| 1536 | bool inactive = !active; |
| 1537 | bool old; |
| 1538 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1539 | if (ctrl == NULL) |
| 1540 | return; |
| 1541 | |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 1542 | if (inactive) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1543 | /* set V4L2_CTRL_FLAG_INACTIVE */ |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 1544 | old = test_and_set_bit(4, &ctrl->flags); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1545 | else |
| 1546 | /* clear V4L2_CTRL_FLAG_INACTIVE */ |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 1547 | old = test_and_clear_bit(4, &ctrl->flags); |
| 1548 | if (old != inactive) |
| 1549 | send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1550 | } |
| 1551 | EXPORT_SYMBOL(v4l2_ctrl_activate); |
| 1552 | |
| 1553 | /* Grab/ungrab a control. |
| 1554 | Typically used when streaming starts and you want to grab controls, |
| 1555 | preventing the user from changing them. |
| 1556 | |
| 1557 | Just call this and the framework will block any attempts to change |
| 1558 | these controls. */ |
| 1559 | void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed) |
| 1560 | { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 1561 | bool old; |
| 1562 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1563 | if (ctrl == NULL) |
| 1564 | return; |
| 1565 | |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 1566 | v4l2_ctrl_lock(ctrl); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1567 | if (grabbed) |
| 1568 | /* set V4L2_CTRL_FLAG_GRABBED */ |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 1569 | old = test_and_set_bit(1, &ctrl->flags); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1570 | else |
| 1571 | /* clear V4L2_CTRL_FLAG_GRABBED */ |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 1572 | old = test_and_clear_bit(1, &ctrl->flags); |
| 1573 | if (old != grabbed) |
| 1574 | send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS); |
| 1575 | v4l2_ctrl_unlock(ctrl); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1576 | } |
| 1577 | EXPORT_SYMBOL(v4l2_ctrl_grab); |
| 1578 | |
| 1579 | /* Log the control name and value */ |
| 1580 | static void log_ctrl(const struct v4l2_ctrl *ctrl, |
| 1581 | const char *prefix, const char *colon) |
| 1582 | { |
| 1583 | int fl_inact = ctrl->flags & V4L2_CTRL_FLAG_INACTIVE; |
| 1584 | int fl_grabbed = ctrl->flags & V4L2_CTRL_FLAG_GRABBED; |
| 1585 | |
| 1586 | if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY)) |
| 1587 | return; |
| 1588 | if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) |
| 1589 | return; |
| 1590 | |
| 1591 | printk(KERN_INFO "%s%s%s: ", prefix, colon, ctrl->name); |
| 1592 | |
| 1593 | switch (ctrl->type) { |
| 1594 | case V4L2_CTRL_TYPE_INTEGER: |
| 1595 | printk(KERN_CONT "%d", ctrl->cur.val); |
| 1596 | break; |
| 1597 | case V4L2_CTRL_TYPE_BOOLEAN: |
| 1598 | printk(KERN_CONT "%s", ctrl->cur.val ? "true" : "false"); |
| 1599 | break; |
| 1600 | case V4L2_CTRL_TYPE_MENU: |
| 1601 | printk(KERN_CONT "%s", ctrl->qmenu[ctrl->cur.val]); |
| 1602 | break; |
Hans Verkuil | fa4d709 | 2011-05-23 04:07:05 -0300 | [diff] [blame] | 1603 | case V4L2_CTRL_TYPE_BITMASK: |
| 1604 | printk(KERN_CONT "0x%08x", ctrl->cur.val); |
| 1605 | break; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1606 | case V4L2_CTRL_TYPE_INTEGER64: |
| 1607 | printk(KERN_CONT "%lld", ctrl->cur.val64); |
| 1608 | break; |
| 1609 | case V4L2_CTRL_TYPE_STRING: |
| 1610 | printk(KERN_CONT "%s", ctrl->cur.string); |
| 1611 | break; |
| 1612 | default: |
| 1613 | printk(KERN_CONT "unknown type %d", ctrl->type); |
| 1614 | break; |
| 1615 | } |
| 1616 | if (fl_inact && fl_grabbed) |
| 1617 | printk(KERN_CONT " (inactive, grabbed)\n"); |
| 1618 | else if (fl_inact) |
| 1619 | printk(KERN_CONT " (inactive)\n"); |
| 1620 | else if (fl_grabbed) |
| 1621 | printk(KERN_CONT " (grabbed)\n"); |
| 1622 | else |
| 1623 | printk(KERN_CONT "\n"); |
| 1624 | } |
| 1625 | |
| 1626 | /* Log all controls owned by the handler */ |
| 1627 | void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, |
| 1628 | const char *prefix) |
| 1629 | { |
| 1630 | struct v4l2_ctrl *ctrl; |
| 1631 | const char *colon = ""; |
| 1632 | int len; |
| 1633 | |
| 1634 | if (hdl == NULL) |
| 1635 | return; |
| 1636 | if (prefix == NULL) |
| 1637 | prefix = ""; |
| 1638 | len = strlen(prefix); |
| 1639 | if (len && prefix[len - 1] != ' ') |
| 1640 | colon = ": "; |
| 1641 | mutex_lock(&hdl->lock); |
| 1642 | list_for_each_entry(ctrl, &hdl->ctrls, node) |
| 1643 | if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED)) |
| 1644 | log_ctrl(ctrl, prefix, colon); |
| 1645 | mutex_unlock(&hdl->lock); |
| 1646 | } |
| 1647 | EXPORT_SYMBOL(v4l2_ctrl_handler_log_status); |
| 1648 | |
| 1649 | /* Call s_ctrl for all controls owned by the handler */ |
| 1650 | int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl) |
| 1651 | { |
| 1652 | struct v4l2_ctrl *ctrl; |
| 1653 | int ret = 0; |
| 1654 | |
| 1655 | if (hdl == NULL) |
| 1656 | return 0; |
| 1657 | mutex_lock(&hdl->lock); |
| 1658 | list_for_each_entry(ctrl, &hdl->ctrls, node) |
| 1659 | ctrl->done = false; |
| 1660 | |
| 1661 | list_for_each_entry(ctrl, &hdl->ctrls, node) { |
| 1662 | struct v4l2_ctrl *master = ctrl->cluster[0]; |
| 1663 | int i; |
| 1664 | |
| 1665 | /* Skip if this control was already handled by a cluster. */ |
Hans Verkuil | 71c6c4c | 2011-06-14 11:01:52 -0300 | [diff] [blame] | 1666 | /* Skip button controls and read-only controls. */ |
| 1667 | if (ctrl->done || ctrl->type == V4L2_CTRL_TYPE_BUTTON || |
| 1668 | (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1669 | continue; |
| 1670 | |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 1671 | for (i = 0; i < master->ncontrols; i++) { |
| 1672 | if (master->cluster[i]) { |
| 1673 | cur_to_new(master->cluster[i]); |
| 1674 | master->cluster[i]->is_new = 1; |
Hans Verkuil | 71c6c4c | 2011-06-14 11:01:52 -0300 | [diff] [blame] | 1675 | master->cluster[i]->done = true; |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 1676 | } |
| 1677 | } |
Hans Verkuil | 54c911e | 2011-05-25 06:04:58 -0300 | [diff] [blame] | 1678 | ret = call_op(master, s_ctrl); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1679 | if (ret) |
| 1680 | break; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1681 | } |
| 1682 | mutex_unlock(&hdl->lock); |
| 1683 | return ret; |
| 1684 | } |
| 1685 | EXPORT_SYMBOL(v4l2_ctrl_handler_setup); |
| 1686 | |
| 1687 | /* Implement VIDIOC_QUERYCTRL */ |
| 1688 | int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc) |
| 1689 | { |
| 1690 | u32 id = qc->id & V4L2_CTRL_ID_MASK; |
| 1691 | struct v4l2_ctrl_ref *ref; |
| 1692 | struct v4l2_ctrl *ctrl; |
| 1693 | |
| 1694 | if (hdl == NULL) |
| 1695 | return -EINVAL; |
| 1696 | |
| 1697 | mutex_lock(&hdl->lock); |
| 1698 | |
| 1699 | /* Try to find it */ |
| 1700 | ref = find_ref(hdl, id); |
| 1701 | |
| 1702 | if ((qc->id & V4L2_CTRL_FLAG_NEXT_CTRL) && !list_empty(&hdl->ctrl_refs)) { |
| 1703 | /* Find the next control with ID > qc->id */ |
| 1704 | |
| 1705 | /* Did we reach the end of the control list? */ |
| 1706 | if (id >= node2id(hdl->ctrl_refs.prev)) { |
| 1707 | ref = NULL; /* Yes, so there is no next control */ |
| 1708 | } else if (ref) { |
| 1709 | /* We found a control with the given ID, so just get |
| 1710 | the next one in the list. */ |
| 1711 | ref = list_entry(ref->node.next, typeof(*ref), node); |
| 1712 | } else { |
| 1713 | /* No control with the given ID exists, so start |
| 1714 | searching for the next largest ID. We know there |
| 1715 | is one, otherwise the first 'if' above would have |
| 1716 | been true. */ |
| 1717 | list_for_each_entry(ref, &hdl->ctrl_refs, node) |
| 1718 | if (id < ref->ctrl->id) |
| 1719 | break; |
| 1720 | } |
| 1721 | } |
| 1722 | mutex_unlock(&hdl->lock); |
| 1723 | if (!ref) |
| 1724 | return -EINVAL; |
| 1725 | |
| 1726 | ctrl = ref->ctrl; |
| 1727 | memset(qc, 0, sizeof(*qc)); |
Hans Verkuil | 829fb2d | 2011-01-16 11:21:40 -0300 | [diff] [blame] | 1728 | if (id >= V4L2_CID_PRIVATE_BASE) |
| 1729 | qc->id = id; |
| 1730 | else |
| 1731 | qc->id = ctrl->id; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1732 | strlcpy(qc->name, ctrl->name, sizeof(qc->name)); |
| 1733 | qc->minimum = ctrl->minimum; |
| 1734 | qc->maximum = ctrl->maximum; |
| 1735 | qc->default_value = ctrl->default_value; |
Laurent Pinchart | eac9aa0 | 2010-12-07 08:57:25 -0300 | [diff] [blame] | 1736 | if (ctrl->type == V4L2_CTRL_TYPE_MENU) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1737 | qc->step = 1; |
| 1738 | else |
| 1739 | qc->step = ctrl->step; |
| 1740 | qc->flags = ctrl->flags; |
| 1741 | qc->type = ctrl->type; |
| 1742 | return 0; |
| 1743 | } |
| 1744 | EXPORT_SYMBOL(v4l2_queryctrl); |
| 1745 | |
| 1746 | int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) |
| 1747 | { |
Hans Verkuil | 87a0c94 | 2011-02-22 12:31:07 -0300 | [diff] [blame] | 1748 | if (qc->id & V4L2_CTRL_FLAG_NEXT_CTRL) |
| 1749 | return -EINVAL; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1750 | return v4l2_queryctrl(sd->ctrl_handler, qc); |
| 1751 | } |
| 1752 | EXPORT_SYMBOL(v4l2_subdev_queryctrl); |
| 1753 | |
| 1754 | /* Implement VIDIOC_QUERYMENU */ |
| 1755 | int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm) |
| 1756 | { |
| 1757 | struct v4l2_ctrl *ctrl; |
| 1758 | u32 i = qm->index; |
| 1759 | |
| 1760 | ctrl = v4l2_ctrl_find(hdl, qm->id); |
| 1761 | if (!ctrl) |
| 1762 | return -EINVAL; |
| 1763 | |
| 1764 | qm->reserved = 0; |
| 1765 | /* Sanity checks */ |
| 1766 | if (ctrl->qmenu == NULL || |
| 1767 | i < ctrl->minimum || i > ctrl->maximum) |
| 1768 | return -EINVAL; |
| 1769 | /* Use mask to see if this menu item should be skipped */ |
| 1770 | if (ctrl->menu_skip_mask & (1 << i)) |
| 1771 | return -EINVAL; |
| 1772 | /* Empty menu items should also be skipped */ |
| 1773 | if (ctrl->qmenu[i] == NULL || ctrl->qmenu[i][0] == '\0') |
| 1774 | return -EINVAL; |
| 1775 | strlcpy(qm->name, ctrl->qmenu[i], sizeof(qm->name)); |
| 1776 | return 0; |
| 1777 | } |
| 1778 | EXPORT_SYMBOL(v4l2_querymenu); |
| 1779 | |
| 1780 | int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm) |
| 1781 | { |
| 1782 | return v4l2_querymenu(sd->ctrl_handler, qm); |
| 1783 | } |
| 1784 | EXPORT_SYMBOL(v4l2_subdev_querymenu); |
| 1785 | |
| 1786 | |
| 1787 | |
| 1788 | /* Some general notes on the atomic requirements of VIDIOC_G/TRY/S_EXT_CTRLS: |
| 1789 | |
| 1790 | It is not a fully atomic operation, just best-effort only. After all, if |
| 1791 | multiple controls have to be set through multiple i2c writes (for example) |
| 1792 | then some initial writes may succeed while others fail. Thus leaving the |
| 1793 | system in an inconsistent state. The question is how much effort you are |
| 1794 | willing to spend on trying to make something atomic that really isn't. |
| 1795 | |
| 1796 | From the point of view of an application the main requirement is that |
| 1797 | when you call VIDIOC_S_EXT_CTRLS and some values are invalid then an |
| 1798 | error should be returned without actually affecting any controls. |
| 1799 | |
| 1800 | If all the values are correct, then it is acceptable to just give up |
| 1801 | in case of low-level errors. |
| 1802 | |
| 1803 | It is important though that the application can tell when only a partial |
| 1804 | configuration was done. The way we do that is through the error_idx field |
| 1805 | of struct v4l2_ext_controls: if that is equal to the count field then no |
| 1806 | controls were affected. Otherwise all controls before that index were |
| 1807 | successful in performing their 'get' or 'set' operation, the control at |
| 1808 | the given index failed, and you don't know what happened with the controls |
| 1809 | after the failed one. Since if they were part of a control cluster they |
| 1810 | could have been successfully processed (if a cluster member was encountered |
| 1811 | at index < error_idx), they could have failed (if a cluster member was at |
| 1812 | error_idx), or they may not have been processed yet (if the first cluster |
| 1813 | member appeared after error_idx). |
| 1814 | |
| 1815 | It is all fairly theoretical, though. In practice all you can do is to |
| 1816 | bail out. If error_idx == count, then it is an application bug. If |
| 1817 | error_idx < count then it is only an application bug if the error code was |
| 1818 | EBUSY. That usually means that something started streaming just when you |
| 1819 | tried to set the controls. In all other cases it is a driver/hardware |
| 1820 | problem and all you can do is to retry or bail out. |
| 1821 | |
| 1822 | Note that these rules do not apply to VIDIOC_TRY_EXT_CTRLS: since that |
| 1823 | never modifies controls the error_idx is just set to whatever control |
| 1824 | has an invalid value. |
| 1825 | */ |
| 1826 | |
| 1827 | /* Prepare for the extended g/s/try functions. |
| 1828 | Find the controls in the control array and do some basic checks. */ |
| 1829 | static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, |
| 1830 | struct v4l2_ext_controls *cs, |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1831 | struct v4l2_ctrl_helper *helpers) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1832 | { |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1833 | struct v4l2_ctrl_helper *h; |
| 1834 | bool have_clusters = false; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1835 | u32 i; |
| 1836 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1837 | for (i = 0, h = helpers; i < cs->count; i++, h++) { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1838 | struct v4l2_ext_control *c = &cs->controls[i]; |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1839 | struct v4l2_ctrl_ref *ref; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1840 | struct v4l2_ctrl *ctrl; |
| 1841 | u32 id = c->id & V4L2_CTRL_ID_MASK; |
| 1842 | |
Hans Verkuil | 37cd3b7 | 2011-06-07 04:40:04 -0300 | [diff] [blame] | 1843 | cs->error_idx = i; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1844 | |
| 1845 | if (cs->ctrl_class && V4L2_CTRL_ID2CLASS(id) != cs->ctrl_class) |
| 1846 | return -EINVAL; |
| 1847 | |
| 1848 | /* Old-style private controls are not allowed for |
| 1849 | extended controls */ |
| 1850 | if (id >= V4L2_CID_PRIVATE_BASE) |
| 1851 | return -EINVAL; |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1852 | ref = find_ref_lock(hdl, id); |
| 1853 | if (ref == NULL) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1854 | return -EINVAL; |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1855 | ctrl = ref->ctrl; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1856 | if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED) |
| 1857 | return -EINVAL; |
| 1858 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1859 | if (ctrl->cluster[0]->ncontrols > 1) |
| 1860 | have_clusters = true; |
| 1861 | if (ctrl->cluster[0] != ctrl) |
| 1862 | ref = find_ref_lock(hdl, ctrl->cluster[0]->id); |
| 1863 | /* Store the ref to the master control of the cluster */ |
| 1864 | h->mref = ref; |
| 1865 | h->ctrl = ctrl; |
| 1866 | /* Initially set next to 0, meaning that there is no other |
| 1867 | control in this helper array belonging to the same |
| 1868 | cluster */ |
| 1869 | h->next = 0; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1870 | } |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1871 | |
| 1872 | /* We are done if there were no controls that belong to a multi- |
| 1873 | control cluster. */ |
| 1874 | if (!have_clusters) |
| 1875 | return 0; |
| 1876 | |
| 1877 | /* The code below figures out in O(n) time which controls in the list |
| 1878 | belong to the same cluster. */ |
| 1879 | |
| 1880 | /* This has to be done with the handler lock taken. */ |
| 1881 | mutex_lock(&hdl->lock); |
| 1882 | |
| 1883 | /* First zero the helper field in the master control references */ |
| 1884 | for (i = 0; i < cs->count; i++) |
| 1885 | helpers[i].mref->helper = 0; |
| 1886 | for (i = 0, h = helpers; i < cs->count; i++, h++) { |
| 1887 | struct v4l2_ctrl_ref *mref = h->mref; |
| 1888 | |
| 1889 | /* If the mref->helper is set, then it points to an earlier |
| 1890 | helper that belongs to the same cluster. */ |
| 1891 | if (mref->helper) { |
| 1892 | /* Set the next field of mref->helper to the current |
| 1893 | index: this means that that earlier helper now |
| 1894 | points to the next helper in the same cluster. */ |
| 1895 | mref->helper->next = i; |
| 1896 | /* mref should be set only for the first helper in the |
| 1897 | cluster, clear the others. */ |
| 1898 | h->mref = NULL; |
| 1899 | } |
| 1900 | /* Point the mref helper to the current helper struct. */ |
| 1901 | mref->helper = h; |
| 1902 | } |
| 1903 | mutex_unlock(&hdl->lock); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1904 | return 0; |
| 1905 | } |
| 1906 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1907 | /* Handles the corner case where cs->count == 0. It checks whether the |
| 1908 | specified control class exists. If that class ID is 0, then it checks |
| 1909 | whether there are any controls at all. */ |
| 1910 | static int class_check(struct v4l2_ctrl_handler *hdl, u32 ctrl_class) |
| 1911 | { |
| 1912 | if (ctrl_class == 0) |
| 1913 | return list_empty(&hdl->ctrl_refs) ? -EINVAL : 0; |
| 1914 | return find_ref_lock(hdl, ctrl_class | 1) ? 0 : -EINVAL; |
| 1915 | } |
| 1916 | |
| 1917 | |
| 1918 | |
| 1919 | /* Get extended controls. Allocates the helpers array if needed. */ |
| 1920 | int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) |
| 1921 | { |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1922 | struct v4l2_ctrl_helper helper[4]; |
| 1923 | struct v4l2_ctrl_helper *helpers = helper; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1924 | int ret; |
Hans Verkuil | ddac5c1 | 2011-06-10 05:43:34 -0300 | [diff] [blame] | 1925 | int i, j; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1926 | |
| 1927 | cs->error_idx = cs->count; |
| 1928 | cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class); |
| 1929 | |
| 1930 | if (hdl == NULL) |
| 1931 | return -EINVAL; |
| 1932 | |
| 1933 | if (cs->count == 0) |
| 1934 | return class_check(hdl, cs->ctrl_class); |
| 1935 | |
| 1936 | if (cs->count > ARRAY_SIZE(helper)) { |
| 1937 | helpers = kmalloc(sizeof(helper[0]) * cs->count, GFP_KERNEL); |
| 1938 | if (helpers == NULL) |
| 1939 | return -ENOMEM; |
| 1940 | } |
| 1941 | |
Hans Verkuil | 37cd3b7 | 2011-06-07 04:40:04 -0300 | [diff] [blame] | 1942 | ret = prepare_ext_ctrls(hdl, cs, helpers); |
| 1943 | cs->error_idx = cs->count; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1944 | |
| 1945 | for (i = 0; !ret && i < cs->count; i++) |
| 1946 | if (helpers[i].ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) |
| 1947 | ret = -EACCES; |
| 1948 | |
| 1949 | for (i = 0; !ret && i < cs->count; i++) { |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1950 | int (*ctrl_to_user)(struct v4l2_ext_control *c, |
| 1951 | struct v4l2_ctrl *ctrl) = cur_to_user; |
| 1952 | struct v4l2_ctrl *master; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1953 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1954 | if (helpers[i].mref == NULL) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1955 | continue; |
| 1956 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1957 | master = helpers[i].mref->ctrl; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1958 | cs->error_idx = i; |
| 1959 | |
| 1960 | v4l2_ctrl_lock(master); |
Hans Verkuil | ddac5c1 | 2011-06-10 05:43:34 -0300 | [diff] [blame] | 1961 | |
| 1962 | /* g_volatile_ctrl will update the new control values */ |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1963 | if (has_op(master, g_volatile_ctrl) && !is_cur_manual(master)) { |
Hans Verkuil | ddac5c1 | 2011-06-10 05:43:34 -0300 | [diff] [blame] | 1964 | for (j = 0; j < master->ncontrols; j++) |
| 1965 | cur_to_new(master->cluster[j]); |
Hans Verkuil | 54c911e | 2011-05-25 06:04:58 -0300 | [diff] [blame] | 1966 | ret = call_op(master, g_volatile_ctrl); |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1967 | ctrl_to_user = new_to_user; |
Hans Verkuil | ddac5c1 | 2011-06-10 05:43:34 -0300 | [diff] [blame] | 1968 | } |
| 1969 | /* If OK, then copy the current (for non-volatile controls) |
| 1970 | or the new (for volatile controls) control values to the |
| 1971 | caller */ |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 1972 | if (!ret) { |
| 1973 | u32 idx = i; |
| 1974 | |
| 1975 | do { |
| 1976 | ret = ctrl_to_user(cs->controls + idx, |
| 1977 | helpers[idx].ctrl); |
| 1978 | idx = helpers[idx].next; |
| 1979 | } while (!ret && idx); |
| 1980 | } |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1981 | v4l2_ctrl_unlock(master); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | if (cs->count > ARRAY_SIZE(helper)) |
| 1985 | kfree(helpers); |
| 1986 | return ret; |
| 1987 | } |
| 1988 | EXPORT_SYMBOL(v4l2_g_ext_ctrls); |
| 1989 | |
| 1990 | int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs) |
| 1991 | { |
| 1992 | return v4l2_g_ext_ctrls(sd->ctrl_handler, cs); |
| 1993 | } |
| 1994 | EXPORT_SYMBOL(v4l2_subdev_g_ext_ctrls); |
| 1995 | |
| 1996 | /* Helper function to get a single control */ |
| 1997 | static int get_ctrl(struct v4l2_ctrl *ctrl, s32 *val) |
| 1998 | { |
| 1999 | struct v4l2_ctrl *master = ctrl->cluster[0]; |
| 2000 | int ret = 0; |
Hans Verkuil | ddac5c1 | 2011-06-10 05:43:34 -0300 | [diff] [blame] | 2001 | int i; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2002 | |
| 2003 | if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) |
| 2004 | return -EACCES; |
| 2005 | |
| 2006 | v4l2_ctrl_lock(master); |
| 2007 | /* g_volatile_ctrl will update the current control values */ |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 2008 | if (ctrl->is_volatile && !is_cur_manual(master)) { |
Hans Verkuil | ddac5c1 | 2011-06-10 05:43:34 -0300 | [diff] [blame] | 2009 | for (i = 0; i < master->ncontrols; i++) |
| 2010 | cur_to_new(master->cluster[i]); |
Hans Verkuil | 54c911e | 2011-05-25 06:04:58 -0300 | [diff] [blame] | 2011 | ret = call_op(master, g_volatile_ctrl); |
Hans Verkuil | ddac5c1 | 2011-06-10 05:43:34 -0300 | [diff] [blame] | 2012 | *val = ctrl->val; |
| 2013 | } else { |
| 2014 | *val = ctrl->cur.val; |
| 2015 | } |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2016 | v4l2_ctrl_unlock(master); |
| 2017 | return ret; |
| 2018 | } |
| 2019 | |
| 2020 | int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control) |
| 2021 | { |
| 2022 | struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); |
| 2023 | |
| 2024 | if (ctrl == NULL || !type_is_int(ctrl)) |
| 2025 | return -EINVAL; |
| 2026 | return get_ctrl(ctrl, &control->value); |
| 2027 | } |
| 2028 | EXPORT_SYMBOL(v4l2_g_ctrl); |
| 2029 | |
| 2030 | int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *control) |
| 2031 | { |
| 2032 | return v4l2_g_ctrl(sd->ctrl_handler, control); |
| 2033 | } |
| 2034 | EXPORT_SYMBOL(v4l2_subdev_g_ctrl); |
| 2035 | |
| 2036 | s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl) |
| 2037 | { |
| 2038 | s32 val = 0; |
| 2039 | |
| 2040 | /* It's a driver bug if this happens. */ |
| 2041 | WARN_ON(!type_is_int(ctrl)); |
| 2042 | get_ctrl(ctrl, &val); |
| 2043 | return val; |
| 2044 | } |
| 2045 | EXPORT_SYMBOL(v4l2_ctrl_g_ctrl); |
| 2046 | |
| 2047 | |
| 2048 | /* Core function that calls try/s_ctrl and ensures that the new value is |
| 2049 | copied to the current value on a set. |
| 2050 | Must be called with ctrl->handler->lock held. */ |
Hans Verkuil | e640258 | 2011-06-14 10:56:42 -0300 | [diff] [blame] | 2051 | static int try_or_set_cluster(struct v4l2_fh *fh, |
| 2052 | struct v4l2_ctrl *master, bool set) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2053 | { |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 2054 | bool update_flag; |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2055 | int ret; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2056 | int i; |
| 2057 | |
| 2058 | /* Go through the cluster and either validate the new value or |
| 2059 | (if no new value was set), copy the current value to the new |
| 2060 | value, ensuring a consistent view for the control ops when |
| 2061 | called. */ |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2062 | for (i = 0; i < master->ncontrols; i++) { |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2063 | struct v4l2_ctrl *ctrl = master->cluster[i]; |
| 2064 | |
| 2065 | if (ctrl == NULL) |
| 2066 | continue; |
| 2067 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2068 | if (!ctrl->is_new) { |
| 2069 | cur_to_new(ctrl); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2070 | continue; |
| 2071 | } |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2072 | /* Check again: it may have changed since the |
| 2073 | previous check in try_or_set_ext_ctrls(). */ |
| 2074 | if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) |
| 2075 | return -EBUSY; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2076 | } |
| 2077 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2078 | ret = call_op(master, try_ctrl); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2079 | |
| 2080 | /* Don't set if there is no change */ |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 2081 | if (ret || !set || !cluster_changed(master)) |
| 2082 | return ret; |
| 2083 | ret = call_op(master, s_ctrl); |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 2084 | if (ret) |
| 2085 | return ret; |
| 2086 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2087 | /* If OK, then make the new values permanent. */ |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 2088 | update_flag = is_cur_manual(master) != is_new_manual(master); |
| 2089 | for (i = 0; i < master->ncontrols; i++) |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2090 | new_to_cur(fh, master->cluster[i], update_flag && i > 0); |
Hans Verkuil | 72d877c | 2011-06-10 05:44:36 -0300 | [diff] [blame] | 2091 | return 0; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2092 | } |
| 2093 | |
Hans Verkuil | e640258 | 2011-06-14 10:56:42 -0300 | [diff] [blame] | 2094 | /* Validate controls. */ |
| 2095 | static int validate_ctrls(struct v4l2_ext_controls *cs, |
| 2096 | struct v4l2_ctrl_helper *helpers, bool set) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2097 | { |
Hans Verkuil | e640258 | 2011-06-14 10:56:42 -0300 | [diff] [blame] | 2098 | unsigned i; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2099 | int ret = 0; |
| 2100 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2101 | cs->error_idx = cs->count; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2102 | for (i = 0; i < cs->count; i++) { |
| 2103 | struct v4l2_ctrl *ctrl = helpers[i].ctrl; |
| 2104 | |
Hans Verkuil | e640258 | 2011-06-14 10:56:42 -0300 | [diff] [blame] | 2105 | cs->error_idx = i; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2106 | |
| 2107 | if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) |
| 2108 | return -EACCES; |
| 2109 | /* This test is also done in try_set_control_cluster() which |
| 2110 | is called in atomic context, so that has the final say, |
| 2111 | but it makes sense to do an up-front check as well. Once |
| 2112 | an error occurs in try_set_control_cluster() some other |
| 2113 | controls may have been set already and we want to do a |
| 2114 | best-effort to avoid that. */ |
| 2115 | if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) |
| 2116 | return -EBUSY; |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2117 | ret = validate_new(ctrl, &cs->controls[i]); |
| 2118 | if (ret) |
| 2119 | return ret; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2120 | } |
Hans Verkuil | e640258 | 2011-06-14 10:56:42 -0300 | [diff] [blame] | 2121 | return 0; |
| 2122 | } |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2123 | |
Hans Verkuil | e640258 | 2011-06-14 10:56:42 -0300 | [diff] [blame] | 2124 | /* Try or try-and-set controls */ |
| 2125 | static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, |
| 2126 | struct v4l2_ext_controls *cs, |
| 2127 | bool set) |
| 2128 | { |
| 2129 | struct v4l2_ctrl_helper helper[4]; |
| 2130 | struct v4l2_ctrl_helper *helpers = helper; |
| 2131 | unsigned i, j; |
| 2132 | int ret; |
| 2133 | |
| 2134 | cs->error_idx = cs->count; |
| 2135 | cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class); |
| 2136 | |
| 2137 | if (hdl == NULL) |
| 2138 | return -EINVAL; |
| 2139 | |
| 2140 | if (cs->count == 0) |
| 2141 | return class_check(hdl, cs->ctrl_class); |
| 2142 | |
| 2143 | if (cs->count > ARRAY_SIZE(helper)) { |
| 2144 | helpers = kmalloc(sizeof(helper[0]) * cs->count, GFP_KERNEL); |
| 2145 | if (!helpers) |
| 2146 | return -ENOMEM; |
| 2147 | } |
| 2148 | ret = prepare_ext_ctrls(hdl, cs, helpers); |
| 2149 | if (!ret) |
| 2150 | ret = validate_ctrls(cs, helpers, set); |
| 2151 | if (ret && set) |
| 2152 | cs->error_idx = cs->count; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2153 | for (i = 0; !ret && i < cs->count; i++) { |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2154 | struct v4l2_ctrl *master; |
| 2155 | u32 idx = i; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2156 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2157 | if (helpers[i].mref == NULL) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2158 | continue; |
| 2159 | |
Hans Verkuil | 37cd3b7 | 2011-06-07 04:40:04 -0300 | [diff] [blame] | 2160 | cs->error_idx = i; |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2161 | master = helpers[i].mref->ctrl; |
| 2162 | v4l2_ctrl_lock(master); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2163 | |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 2164 | /* Reset the 'is_new' flags of the cluster */ |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2165 | for (j = 0; j < master->ncontrols; j++) |
| 2166 | if (master->cluster[j]) |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 2167 | master->cluster[j]->is_new = 0; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2168 | |
| 2169 | /* Copy the new caller-supplied control values. |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 2170 | user_to_new() sets 'is_new' to 1. */ |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2171 | do { |
| 2172 | ret = user_to_new(cs->controls + idx, helpers[idx].ctrl); |
| 2173 | idx = helpers[idx].next; |
| 2174 | } while (!ret && idx); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2175 | |
| 2176 | if (!ret) |
Hans Verkuil | e640258 | 2011-06-14 10:56:42 -0300 | [diff] [blame] | 2177 | ret = try_or_set_cluster(fh, master, set); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2178 | |
| 2179 | /* Copy the new values back to userspace. */ |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2180 | if (!ret) { |
| 2181 | idx = i; |
| 2182 | do { |
Hans Verkuil | adf41b9 | 2011-07-05 06:56:37 -0300 | [diff] [blame] | 2183 | ret = new_to_user(cs->controls + idx, |
Hans Verkuil | e640258 | 2011-06-14 10:56:42 -0300 | [diff] [blame] | 2184 | helpers[idx].ctrl); |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2185 | idx = helpers[idx].next; |
| 2186 | } while (!ret && idx); |
| 2187 | } |
| 2188 | v4l2_ctrl_unlock(master); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2189 | } |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2190 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2191 | if (cs->count > ARRAY_SIZE(helper)) |
| 2192 | kfree(helpers); |
| 2193 | return ret; |
| 2194 | } |
| 2195 | |
| 2196 | int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) |
| 2197 | { |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2198 | return try_set_ext_ctrls(NULL, hdl, cs, false); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2199 | } |
| 2200 | EXPORT_SYMBOL(v4l2_try_ext_ctrls); |
| 2201 | |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2202 | int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, |
| 2203 | struct v4l2_ext_controls *cs) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2204 | { |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2205 | return try_set_ext_ctrls(fh, hdl, cs, true); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2206 | } |
| 2207 | EXPORT_SYMBOL(v4l2_s_ext_ctrls); |
| 2208 | |
| 2209 | int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs) |
| 2210 | { |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2211 | return try_set_ext_ctrls(NULL, sd->ctrl_handler, cs, false); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2212 | } |
| 2213 | EXPORT_SYMBOL(v4l2_subdev_try_ext_ctrls); |
| 2214 | |
| 2215 | int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs) |
| 2216 | { |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2217 | return try_set_ext_ctrls(NULL, sd->ctrl_handler, cs, true); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2218 | } |
| 2219 | EXPORT_SYMBOL(v4l2_subdev_s_ext_ctrls); |
| 2220 | |
| 2221 | /* Helper function for VIDIOC_S_CTRL compatibility */ |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2222 | static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, s32 *val) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2223 | { |
| 2224 | struct v4l2_ctrl *master = ctrl->cluster[0]; |
| 2225 | int ret; |
| 2226 | int i; |
| 2227 | |
Hans Verkuil | eb5b16e | 2011-06-14 10:04:06 -0300 | [diff] [blame] | 2228 | ret = validate_new_int(ctrl, val); |
| 2229 | if (ret) |
| 2230 | return ret; |
| 2231 | |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2232 | v4l2_ctrl_lock(ctrl); |
| 2233 | |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 2234 | /* Reset the 'is_new' flags of the cluster */ |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2235 | for (i = 0; i < master->ncontrols; i++) |
| 2236 | if (master->cluster[i]) |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 2237 | master->cluster[i]->is_new = 0; |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2238 | |
| 2239 | ctrl->val = *val; |
Hans Verkuil | 2a86379 | 2011-01-11 14:45:03 -0300 | [diff] [blame] | 2240 | ctrl->is_new = 1; |
Hans Verkuil | e640258 | 2011-06-14 10:56:42 -0300 | [diff] [blame] | 2241 | ret = try_or_set_cluster(fh, master, true); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2242 | *val = ctrl->cur.val; |
| 2243 | v4l2_ctrl_unlock(ctrl); |
| 2244 | return ret; |
| 2245 | } |
| 2246 | |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2247 | int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, |
| 2248 | struct v4l2_control *control) |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2249 | { |
| 2250 | struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); |
| 2251 | |
| 2252 | if (ctrl == NULL || !type_is_int(ctrl)) |
| 2253 | return -EINVAL; |
| 2254 | |
Hans Verkuil | 7ebbc39 | 2011-06-07 04:50:31 -0300 | [diff] [blame] | 2255 | if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) |
| 2256 | return -EACCES; |
| 2257 | |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2258 | return set_ctrl(fh, ctrl, &control->value); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2259 | } |
| 2260 | EXPORT_SYMBOL(v4l2_s_ctrl); |
| 2261 | |
| 2262 | int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *control) |
| 2263 | { |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2264 | return v4l2_s_ctrl(NULL, sd->ctrl_handler, control); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2265 | } |
| 2266 | EXPORT_SYMBOL(v4l2_subdev_s_ctrl); |
| 2267 | |
| 2268 | int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val) |
| 2269 | { |
| 2270 | /* It's a driver bug if this happens. */ |
| 2271 | WARN_ON(!type_is_int(ctrl)); |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 2272 | return set_ctrl(NULL, ctrl, &val); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 2273 | } |
| 2274 | EXPORT_SYMBOL(v4l2_ctrl_s_ctrl); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2275 | |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 2276 | void v4l2_ctrl_add_event(struct v4l2_ctrl *ctrl, |
| 2277 | struct v4l2_subscribed_event *sev) |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2278 | { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2279 | v4l2_ctrl_lock(ctrl); |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 2280 | list_add_tail(&sev->node, &ctrl->ev_subs); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2281 | if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS && |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 2282 | (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2283 | struct v4l2_event ev; |
Hans Verkuil | c12fcfd | 2011-06-14 02:42:45 -0300 | [diff] [blame] | 2284 | u32 changes = V4L2_EVENT_CTRL_CH_FLAGS; |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2285 | |
Hans Verkuil | c12fcfd | 2011-06-14 02:42:45 -0300 | [diff] [blame] | 2286 | if (!(ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)) |
| 2287 | changes |= V4L2_EVENT_CTRL_CH_VALUE; |
| 2288 | fill_event(&ev, ctrl, changes); |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 2289 | v4l2_event_queue_fh(sev->fh, &ev); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2290 | } |
| 2291 | v4l2_ctrl_unlock(ctrl); |
| 2292 | } |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 2293 | EXPORT_SYMBOL(v4l2_ctrl_add_event); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2294 | |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 2295 | void v4l2_ctrl_del_event(struct v4l2_ctrl *ctrl, |
| 2296 | struct v4l2_subscribed_event *sev) |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2297 | { |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2298 | v4l2_ctrl_lock(ctrl); |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 2299 | list_del(&sev->node); |
Hans Verkuil | 6e23939 | 2011-06-07 11:13:44 -0300 | [diff] [blame] | 2300 | v4l2_ctrl_unlock(ctrl); |
| 2301 | } |
Hans Verkuil | 77068d3 | 2011-06-13 18:55:58 -0300 | [diff] [blame] | 2302 | EXPORT_SYMBOL(v4l2_ctrl_del_event); |