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