diff options
Diffstat (limited to 'drivers/media/video/v4l2-ctrls.c')
-rw-r--r-- | drivers/media/video/v4l2-ctrls.c | 826 |
1 files changed, 626 insertions, 200 deletions
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c index 2412f08527aa..06b6014d4fb4 100644 --- a/drivers/media/video/v4l2-ctrls.c +++ b/drivers/media/video/v4l2-ctrls.c | |||
@@ -23,17 +23,39 @@ | |||
23 | #include <media/v4l2-ioctl.h> | 23 | #include <media/v4l2-ioctl.h> |
24 | #include <media/v4l2-device.h> | 24 | #include <media/v4l2-device.h> |
25 | #include <media/v4l2-ctrls.h> | 25 | #include <media/v4l2-ctrls.h> |
26 | #include <media/v4l2-event.h> | ||
26 | #include <media/v4l2-dev.h> | 27 | #include <media/v4l2-dev.h> |
27 | 28 | ||
29 | #define has_op(master, op) \ | ||
30 | (master->ops && master->ops->op) | ||
31 | #define call_op(master, op) \ | ||
32 | (has_op(master, op) ? master->ops->op(master) : 0) | ||
33 | |||
28 | /* Internal temporary helper struct, one for each v4l2_ext_control */ | 34 | /* Internal temporary helper struct, one for each v4l2_ext_control */ |
29 | struct ctrl_helper { | 35 | struct v4l2_ctrl_helper { |
36 | /* Pointer to the control reference of the master control */ | ||
37 | struct v4l2_ctrl_ref *mref; | ||
30 | /* The control corresponding to the v4l2_ext_control ID field. */ | 38 | /* The control corresponding to the v4l2_ext_control ID field. */ |
31 | struct v4l2_ctrl *ctrl; | 39 | struct v4l2_ctrl *ctrl; |
32 | /* Used internally to mark whether this control was already | 40 | /* v4l2_ext_control index of the next control belonging to the |
33 | processed. */ | 41 | same cluster, or 0 if there isn't any. */ |
34 | bool handled; | 42 | u32 next; |
35 | }; | 43 | }; |
36 | 44 | ||
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 | |||
37 | /* Returns NULL or a character pointer array containing the menu for | 59 | /* Returns NULL or a character pointer array containing the menu for |
38 | the given control ID. The pointer array ends with a NULL pointer. | 60 | the given control ID. The pointer array ends with a NULL pointer. |
39 | An empty string signifies a menu entry that is invalid. This allows | 61 | An empty string signifies a menu entry that is invalid. This allows |
@@ -181,7 +203,7 @@ const char * const *v4l2_ctrl_get_menu(u32 id) | |||
181 | }; | 203 | }; |
182 | static const char * const mpeg_stream_vbi_fmt[] = { | 204 | static const char * const mpeg_stream_vbi_fmt[] = { |
183 | "No VBI", | 205 | "No VBI", |
184 | "Private packet, IVTV format", | 206 | "Private Packet, IVTV Format", |
185 | NULL | 207 | NULL |
186 | }; | 208 | }; |
187 | static const char * const camera_power_line_frequency[] = { | 209 | static const char * const camera_power_line_frequency[] = { |
@@ -204,18 +226,130 @@ const char * const *v4l2_ctrl_get_menu(u32 id) | |||
204 | "Negative", | 226 | "Negative", |
205 | "Emboss", | 227 | "Emboss", |
206 | "Sketch", | 228 | "Sketch", |
207 | "Sky blue", | 229 | "Sky Blue", |
208 | "Grass green", | 230 | "Grass Green", |
209 | "Skin whiten", | 231 | "Skin Whiten", |
210 | "Vivid", | 232 | "Vivid", |
211 | NULL | 233 | NULL |
212 | }; | 234 | }; |
213 | static const char * const tune_preemphasis[] = { | 235 | static const char * const tune_preemphasis[] = { |
214 | "No preemphasis", | 236 | "No Preemphasis", |
215 | "50 useconds", | 237 | "50 useconds", |
216 | "75 useconds", | 238 | "75 useconds", |
217 | NULL, | 239 | NULL, |
218 | }; | 240 | }; |
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 | static const char * const flash_led_mode[] = { | ||
343 | "Off", | ||
344 | "Flash", | ||
345 | "Torch", | ||
346 | NULL, | ||
347 | }; | ||
348 | static const char * const flash_strobe_source[] = { | ||
349 | "Software", | ||
350 | "External", | ||
351 | NULL, | ||
352 | }; | ||
219 | 353 | ||
220 | switch (id) { | 354 | switch (id) { |
221 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: | 355 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: |
@@ -256,6 +390,28 @@ const char * const *v4l2_ctrl_get_menu(u32 id) | |||
256 | return colorfx; | 390 | return colorfx; |
257 | case V4L2_CID_TUNE_PREEMPHASIS: | 391 | case V4L2_CID_TUNE_PREEMPHASIS: |
258 | return tune_preemphasis; | 392 | return tune_preemphasis; |
393 | case V4L2_CID_FLASH_LED_MODE: | ||
394 | return flash_led_mode; | ||
395 | case V4L2_CID_FLASH_STROBE_SOURCE: | ||
396 | return flash_strobe_source; | ||
397 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: | ||
398 | return header_mode; | ||
399 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: | ||
400 | return multi_slice; | ||
401 | case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: | ||
402 | return entropy_mode; | ||
403 | case V4L2_CID_MPEG_VIDEO_H264_LEVEL: | ||
404 | return mpeg_h264_level; | ||
405 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: | ||
406 | return h264_loop_filter; | ||
407 | case V4L2_CID_MPEG_VIDEO_H264_PROFILE: | ||
408 | return h264_profile; | ||
409 | case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC: | ||
410 | return vui_sar_idc; | ||
411 | case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL: | ||
412 | return mpeg_mpeg4_level; | ||
413 | case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE: | ||
414 | return mpeg4_profile; | ||
259 | default: | 415 | default: |
260 | return NULL; | 416 | return NULL; |
261 | } | 417 | } |
@@ -307,6 +463,8 @@ const char *v4l2_ctrl_get_name(u32 id) | |||
307 | case V4L2_CID_CHROMA_GAIN: return "Chroma Gain"; | 463 | case V4L2_CID_CHROMA_GAIN: return "Chroma Gain"; |
308 | case V4L2_CID_ILLUMINATORS_1: return "Illuminator 1"; | 464 | case V4L2_CID_ILLUMINATORS_1: return "Illuminator 1"; |
309 | case V4L2_CID_ILLUMINATORS_2: return "Illuminator 2"; | 465 | case V4L2_CID_ILLUMINATORS_2: return "Illuminator 2"; |
466 | case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE: return "Minimum Number of Capture Buffers"; | ||
467 | case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT: return "Minimum Number of Output Buffers"; | ||
310 | 468 | ||
311 | /* MPEG controls */ | 469 | /* MPEG controls */ |
312 | /* Keep the order of the 'case's the same as in videodev2.h! */ | 470 | /* Keep the order of the 'case's the same as in videodev2.h! */ |
@@ -343,6 +501,48 @@ const char *v4l2_ctrl_get_name(u32 id) | |||
343 | case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation"; | 501 | case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation"; |
344 | case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute"; | 502 | case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute"; |
345 | case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV"; | 503 | case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV"; |
504 | case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE: return "Decoder Slice Interface"; | ||
505 | case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER: return "MPEG4 Loop Filter Enable"; | ||
506 | case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB: return "The Number of Intra Refresh MBs"; | ||
507 | case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE: return "Frame Level Rate Control Enable"; | ||
508 | case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE: return "H264 MB Level Rate Control"; | ||
509 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: return "Sequence Header Mode"; | ||
510 | case V4L2_CID_MPEG_VIDEO_MAX_REF_PIC: return "The Max Number of Reference Picture"; | ||
511 | case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP: return "H263 I-Frame QP Value"; | ||
512 | case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP: return "H263 P frame QP Value"; | ||
513 | case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP: return "H263 B frame QP Value"; | ||
514 | case V4L2_CID_MPEG_VIDEO_H263_MIN_QP: return "H263 Minimum QP Value"; | ||
515 | case V4L2_CID_MPEG_VIDEO_H263_MAX_QP: return "H263 Maximum QP Value"; | ||
516 | case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: return "H264 I-Frame QP Value"; | ||
517 | case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: return "H264 P frame QP Value"; | ||
518 | case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP: return "H264 B frame QP Value"; | ||
519 | case V4L2_CID_MPEG_VIDEO_H264_MAX_QP: return "H264 Maximum QP Value"; | ||
520 | case V4L2_CID_MPEG_VIDEO_H264_MIN_QP: return "H264 Minimum QP Value"; | ||
521 | case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM: return "H264 8x8 Transform Enable"; | ||
522 | case V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE: return "H264 CPB Buffer Size"; | ||
523 | case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: return "H264 Entorpy Mode"; | ||
524 | case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD: return "H264 I Period"; | ||
525 | case V4L2_CID_MPEG_VIDEO_H264_LEVEL: return "H264 Level"; | ||
526 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA: return "H264 Loop Filter Alpha Offset"; | ||
527 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA: return "H264 Loop Filter Beta Offset"; | ||
528 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: return "H264 Loop Filter Mode"; | ||
529 | case V4L2_CID_MPEG_VIDEO_H264_PROFILE: return "H264 Profile"; | ||
530 | case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT: return "Vertical Size of SAR"; | ||
531 | case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH: return "Horizontal Size of SAR"; | ||
532 | case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE: return "Aspect Ratio VUI Enable"; | ||
533 | case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC: return "VUI Aspect Ratio IDC"; | ||
534 | case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP: return "MPEG4 I-Frame QP Value"; | ||
535 | case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP: return "MPEG4 P frame QP Value"; | ||
536 | case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP: return "MPEG4 B frame QP Value"; | ||
537 | case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP: return "MPEG4 Minimum QP Value"; | ||
538 | case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP: return "MPEG4 Maximum QP Value"; | ||
539 | case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL: return "MPEG4 Level"; | ||
540 | case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE: return "MPEG4 Profile"; | ||
541 | case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL: return "Quarter Pixel Search Enable"; | ||
542 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: return "The Maximum Bytes Per Slice"; | ||
543 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: return "The Number of MB in a Slice"; | ||
544 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: return "The Slice Partitioning Method"; | ||
545 | case V4L2_CID_MPEG_VIDEO_VBV_SIZE: return "VBV Buffer Size"; | ||
346 | 546 | ||
347 | /* CAMERA controls */ | 547 | /* CAMERA controls */ |
348 | /* Keep the order of the 'case's the same as in videodev2.h! */ | 548 | /* Keep the order of the 'case's the same as in videodev2.h! */ |
@@ -389,6 +589,21 @@ const char *v4l2_ctrl_get_name(u32 id) | |||
389 | case V4L2_CID_TUNE_POWER_LEVEL: return "Tune Power Level"; | 589 | case V4L2_CID_TUNE_POWER_LEVEL: return "Tune Power Level"; |
390 | case V4L2_CID_TUNE_ANTENNA_CAPACITOR: return "Tune Antenna Capacitor"; | 590 | case V4L2_CID_TUNE_ANTENNA_CAPACITOR: return "Tune Antenna Capacitor"; |
391 | 591 | ||
592 | /* Flash controls */ | ||
593 | case V4L2_CID_FLASH_CLASS: return "Flash controls"; | ||
594 | case V4L2_CID_FLASH_LED_MODE: return "LED mode"; | ||
595 | case V4L2_CID_FLASH_STROBE_SOURCE: return "Strobe source"; | ||
596 | case V4L2_CID_FLASH_STROBE: return "Strobe"; | ||
597 | case V4L2_CID_FLASH_STROBE_STOP: return "Stop strobe"; | ||
598 | case V4L2_CID_FLASH_STROBE_STATUS: return "Strobe status"; | ||
599 | case V4L2_CID_FLASH_TIMEOUT: return "Strobe timeout"; | ||
600 | case V4L2_CID_FLASH_INTENSITY: return "Intensity, flash mode"; | ||
601 | case V4L2_CID_FLASH_TORCH_INTENSITY: return "Intensity, torch mode"; | ||
602 | case V4L2_CID_FLASH_INDICATOR_INTENSITY: return "Intensity, indicator"; | ||
603 | case V4L2_CID_FLASH_FAULT: return "Faults"; | ||
604 | case V4L2_CID_FLASH_CHARGE: return "Charge"; | ||
605 | case V4L2_CID_FLASH_READY: return "Ready to strobe"; | ||
606 | |||
392 | default: | 607 | default: |
393 | return NULL; | 608 | return NULL; |
394 | } | 609 | } |
@@ -423,12 +638,24 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, | |||
423 | case V4L2_CID_PILOT_TONE_ENABLED: | 638 | case V4L2_CID_PILOT_TONE_ENABLED: |
424 | case V4L2_CID_ILLUMINATORS_1: | 639 | case V4L2_CID_ILLUMINATORS_1: |
425 | case V4L2_CID_ILLUMINATORS_2: | 640 | case V4L2_CID_ILLUMINATORS_2: |
641 | case V4L2_CID_FLASH_STROBE_STATUS: | ||
642 | case V4L2_CID_FLASH_CHARGE: | ||
643 | case V4L2_CID_FLASH_READY: | ||
644 | case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER: | ||
645 | case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE: | ||
646 | case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE: | ||
647 | case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE: | ||
648 | case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM: | ||
649 | case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE: | ||
650 | case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL: | ||
426 | *type = V4L2_CTRL_TYPE_BOOLEAN; | 651 | *type = V4L2_CTRL_TYPE_BOOLEAN; |
427 | *min = 0; | 652 | *min = 0; |
428 | *max = *step = 1; | 653 | *max = *step = 1; |
429 | break; | 654 | break; |
430 | case V4L2_CID_PAN_RESET: | 655 | case V4L2_CID_PAN_RESET: |
431 | case V4L2_CID_TILT_RESET: | 656 | case V4L2_CID_TILT_RESET: |
657 | case V4L2_CID_FLASH_STROBE: | ||
658 | case V4L2_CID_FLASH_STROBE_STOP: | ||
432 | *type = V4L2_CTRL_TYPE_BUTTON; | 659 | *type = V4L2_CTRL_TYPE_BUTTON; |
433 | *flags |= V4L2_CTRL_FLAG_WRITE_ONLY; | 660 | *flags |= V4L2_CTRL_FLAG_WRITE_ONLY; |
434 | *min = *max = *step = *def = 0; | 661 | *min = *max = *step = *def = 0; |
@@ -452,6 +679,17 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, | |||
452 | case V4L2_CID_EXPOSURE_AUTO: | 679 | case V4L2_CID_EXPOSURE_AUTO: |
453 | case V4L2_CID_COLORFX: | 680 | case V4L2_CID_COLORFX: |
454 | case V4L2_CID_TUNE_PREEMPHASIS: | 681 | case V4L2_CID_TUNE_PREEMPHASIS: |
682 | case V4L2_CID_FLASH_LED_MODE: | ||
683 | case V4L2_CID_FLASH_STROBE_SOURCE: | ||
684 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: | ||
685 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: | ||
686 | case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: | ||
687 | case V4L2_CID_MPEG_VIDEO_H264_LEVEL: | ||
688 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: | ||
689 | case V4L2_CID_MPEG_VIDEO_H264_PROFILE: | ||
690 | case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC: | ||
691 | case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL: | ||
692 | case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE: | ||
455 | *type = V4L2_CTRL_TYPE_MENU; | 693 | *type = V4L2_CTRL_TYPE_MENU; |
456 | break; | 694 | break; |
457 | case V4L2_CID_RDS_TX_PS_NAME: | 695 | case V4L2_CID_RDS_TX_PS_NAME: |
@@ -462,6 +700,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, | |||
462 | case V4L2_CID_CAMERA_CLASS: | 700 | case V4L2_CID_CAMERA_CLASS: |
463 | case V4L2_CID_MPEG_CLASS: | 701 | case V4L2_CID_MPEG_CLASS: |
464 | case V4L2_CID_FM_TX_CLASS: | 702 | case V4L2_CID_FM_TX_CLASS: |
703 | case V4L2_CID_FLASH_CLASS: | ||
465 | *type = V4L2_CTRL_TYPE_CTRL_CLASS; | 704 | *type = V4L2_CTRL_TYPE_CTRL_CLASS; |
466 | /* You can neither read not write these */ | 705 | /* You can neither read not write these */ |
467 | *flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY; | 706 | *flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY; |
@@ -474,6 +713,14 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, | |||
474 | /* Max is calculated as RGB888 that is 2^24 */ | 713 | /* Max is calculated as RGB888 that is 2^24 */ |
475 | *max = 0xFFFFFF; | 714 | *max = 0xFFFFFF; |
476 | break; | 715 | break; |
716 | case V4L2_CID_FLASH_FAULT: | ||
717 | *type = V4L2_CTRL_TYPE_BITMASK; | ||
718 | break; | ||
719 | case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE: | ||
720 | case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT: | ||
721 | *type = V4L2_CTRL_TYPE_INTEGER; | ||
722 | *flags |= V4L2_CTRL_FLAG_READ_ONLY; | ||
723 | break; | ||
477 | default: | 724 | default: |
478 | *type = V4L2_CTRL_TYPE_INTEGER; | 725 | *type = V4L2_CTRL_TYPE_INTEGER; |
479 | break; | 726 | break; |
@@ -519,6 +766,10 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, | |||
519 | case V4L2_CID_ZOOM_RELATIVE: | 766 | case V4L2_CID_ZOOM_RELATIVE: |
520 | *flags |= V4L2_CTRL_FLAG_WRITE_ONLY; | 767 | *flags |= V4L2_CTRL_FLAG_WRITE_ONLY; |
521 | break; | 768 | break; |
769 | case V4L2_CID_FLASH_STROBE_STATUS: | ||
770 | case V4L2_CID_FLASH_READY: | ||
771 | *flags |= V4L2_CTRL_FLAG_READ_ONLY; | ||
772 | break; | ||
522 | } | 773 | } |
523 | } | 774 | } |
524 | EXPORT_SYMBOL(v4l2_ctrl_fill); | 775 | EXPORT_SYMBOL(v4l2_ctrl_fill); |
@@ -537,6 +788,42 @@ static bool type_is_int(const struct v4l2_ctrl *ctrl) | |||
537 | } | 788 | } |
538 | } | 789 | } |
539 | 790 | ||
791 | static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl, u32 changes) | ||
792 | { | ||
793 | memset(ev->reserved, 0, sizeof(ev->reserved)); | ||
794 | ev->type = V4L2_EVENT_CTRL; | ||
795 | ev->id = ctrl->id; | ||
796 | ev->u.ctrl.changes = changes; | ||
797 | ev->u.ctrl.type = ctrl->type; | ||
798 | ev->u.ctrl.flags = ctrl->flags; | ||
799 | if (ctrl->type == V4L2_CTRL_TYPE_STRING) | ||
800 | ev->u.ctrl.value64 = 0; | ||
801 | else | ||
802 | ev->u.ctrl.value64 = ctrl->cur.val64; | ||
803 | ev->u.ctrl.minimum = ctrl->minimum; | ||
804 | ev->u.ctrl.maximum = ctrl->maximum; | ||
805 | if (ctrl->type == V4L2_CTRL_TYPE_MENU) | ||
806 | ev->u.ctrl.step = 1; | ||
807 | else | ||
808 | ev->u.ctrl.step = ctrl->step; | ||
809 | ev->u.ctrl.default_value = ctrl->default_value; | ||
810 | } | ||
811 | |||
812 | static void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes) | ||
813 | { | ||
814 | struct v4l2_event ev; | ||
815 | struct v4l2_subscribed_event *sev; | ||
816 | |||
817 | if (list_empty(&ctrl->ev_subs)) | ||
818 | return; | ||
819 | fill_event(&ev, ctrl, changes); | ||
820 | |||
821 | list_for_each_entry(sev, &ctrl->ev_subs, node) | ||
822 | if (sev->fh && (sev->fh != fh || | ||
823 | (sev->flags & V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK))) | ||
824 | v4l2_event_queue_fh(sev->fh, &ev); | ||
825 | } | ||
826 | |||
540 | /* Helper function: copy the current control value back to the caller */ | 827 | /* Helper function: copy the current control value back to the caller */ |
541 | static int cur_to_user(struct v4l2_ext_control *c, | 828 | static int cur_to_user(struct v4l2_ext_control *c, |
542 | struct v4l2_ctrl *ctrl) | 829 | struct v4l2_ctrl *ctrl) |
@@ -624,22 +911,45 @@ static int new_to_user(struct v4l2_ext_control *c, | |||
624 | } | 911 | } |
625 | 912 | ||
626 | /* Copy the new value to the current value. */ | 913 | /* Copy the new value to the current value. */ |
627 | static void new_to_cur(struct v4l2_ctrl *ctrl) | 914 | static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, |
915 | bool update_inactive) | ||
628 | { | 916 | { |
917 | bool changed = false; | ||
918 | |||
629 | if (ctrl == NULL) | 919 | if (ctrl == NULL) |
630 | return; | 920 | return; |
631 | switch (ctrl->type) { | 921 | switch (ctrl->type) { |
922 | case V4L2_CTRL_TYPE_BUTTON: | ||
923 | changed = true; | ||
924 | break; | ||
632 | case V4L2_CTRL_TYPE_STRING: | 925 | case V4L2_CTRL_TYPE_STRING: |
633 | /* strings are always 0-terminated */ | 926 | /* strings are always 0-terminated */ |
927 | changed = strcmp(ctrl->string, ctrl->cur.string); | ||
634 | strcpy(ctrl->cur.string, ctrl->string); | 928 | strcpy(ctrl->cur.string, ctrl->string); |
635 | break; | 929 | break; |
636 | case V4L2_CTRL_TYPE_INTEGER64: | 930 | case V4L2_CTRL_TYPE_INTEGER64: |
931 | changed = ctrl->val64 != ctrl->cur.val64; | ||
637 | ctrl->cur.val64 = ctrl->val64; | 932 | ctrl->cur.val64 = ctrl->val64; |
638 | break; | 933 | break; |
639 | default: | 934 | default: |
935 | changed = ctrl->val != ctrl->cur.val; | ||
640 | ctrl->cur.val = ctrl->val; | 936 | ctrl->cur.val = ctrl->val; |
641 | break; | 937 | break; |
642 | } | 938 | } |
939 | if (update_inactive) { | ||
940 | ctrl->flags &= ~V4L2_CTRL_FLAG_INACTIVE; | ||
941 | if (!is_cur_manual(ctrl->cluster[0])) | ||
942 | ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; | ||
943 | } | ||
944 | if (changed || update_inactive) { | ||
945 | /* If a control was changed that was not one of the controls | ||
946 | modified by the application, then send the event to all. */ | ||
947 | if (!ctrl->is_new) | ||
948 | fh = NULL; | ||
949 | send_event(fh, ctrl, | ||
950 | (changed ? V4L2_EVENT_CTRL_CH_VALUE : 0) | | ||
951 | (update_inactive ? V4L2_EVENT_CTRL_CH_FLAGS : 0)); | ||
952 | } | ||
643 | } | 953 | } |
644 | 954 | ||
645 | /* Copy the current value to the new value */ | 955 | /* Copy the current value to the new value */ |
@@ -692,13 +1002,11 @@ static int cluster_changed(struct v4l2_ctrl *master) | |||
692 | return diff; | 1002 | return diff; |
693 | } | 1003 | } |
694 | 1004 | ||
695 | /* Validate a new control */ | 1005 | /* Validate integer-type control */ |
696 | static int validate_new(struct v4l2_ctrl *ctrl) | 1006 | static int validate_new_int(const struct v4l2_ctrl *ctrl, s32 *pval) |
697 | { | 1007 | { |
698 | s32 val = ctrl->val; | 1008 | s32 val = *pval; |
699 | char *s = ctrl->string; | ||
700 | u32 offset; | 1009 | u32 offset; |
701 | size_t len; | ||
702 | 1010 | ||
703 | switch (ctrl->type) { | 1011 | switch (ctrl->type) { |
704 | case V4L2_CTRL_TYPE_INTEGER: | 1012 | case V4L2_CTRL_TYPE_INTEGER: |
@@ -711,11 +1019,11 @@ static int validate_new(struct v4l2_ctrl *ctrl) | |||
711 | offset = val - ctrl->minimum; | 1019 | offset = val - ctrl->minimum; |
712 | offset = ctrl->step * (offset / ctrl->step); | 1020 | offset = ctrl->step * (offset / ctrl->step); |
713 | val = ctrl->minimum + offset; | 1021 | val = ctrl->minimum + offset; |
714 | ctrl->val = val; | 1022 | *pval = val; |
715 | return 0; | 1023 | return 0; |
716 | 1024 | ||
717 | case V4L2_CTRL_TYPE_BOOLEAN: | 1025 | case V4L2_CTRL_TYPE_BOOLEAN: |
718 | ctrl->val = !!ctrl->val; | 1026 | *pval = !!val; |
719 | return 0; | 1027 | return 0; |
720 | 1028 | ||
721 | case V4L2_CTRL_TYPE_MENU: | 1029 | case V4L2_CTRL_TYPE_MENU: |
@@ -726,11 +1034,35 @@ static int validate_new(struct v4l2_ctrl *ctrl) | |||
726 | return -EINVAL; | 1034 | return -EINVAL; |
727 | return 0; | 1035 | return 0; |
728 | 1036 | ||
1037 | case V4L2_CTRL_TYPE_BITMASK: | ||
1038 | *pval &= ctrl->maximum; | ||
1039 | return 0; | ||
1040 | |||
729 | case V4L2_CTRL_TYPE_BUTTON: | 1041 | case V4L2_CTRL_TYPE_BUTTON: |
730 | case V4L2_CTRL_TYPE_CTRL_CLASS: | 1042 | case V4L2_CTRL_TYPE_CTRL_CLASS: |
731 | ctrl->val64 = 0; | 1043 | *pval = 0; |
732 | return 0; | 1044 | return 0; |
733 | 1045 | ||
1046 | default: | ||
1047 | return -EINVAL; | ||
1048 | } | ||
1049 | } | ||
1050 | |||
1051 | /* Validate a new control */ | ||
1052 | static int validate_new(const struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c) | ||
1053 | { | ||
1054 | char *s = c->string; | ||
1055 | size_t len; | ||
1056 | |||
1057 | switch (ctrl->type) { | ||
1058 | case V4L2_CTRL_TYPE_INTEGER: | ||
1059 | case V4L2_CTRL_TYPE_BOOLEAN: | ||
1060 | case V4L2_CTRL_TYPE_MENU: | ||
1061 | case V4L2_CTRL_TYPE_BITMASK: | ||
1062 | case V4L2_CTRL_TYPE_BUTTON: | ||
1063 | case V4L2_CTRL_TYPE_CTRL_CLASS: | ||
1064 | return validate_new_int(ctrl, &c->value); | ||
1065 | |||
734 | case V4L2_CTRL_TYPE_INTEGER64: | 1066 | case V4L2_CTRL_TYPE_INTEGER64: |
735 | return 0; | 1067 | return 0; |
736 | 1068 | ||
@@ -780,6 +1112,7 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl) | |||
780 | { | 1112 | { |
781 | struct v4l2_ctrl_ref *ref, *next_ref; | 1113 | struct v4l2_ctrl_ref *ref, *next_ref; |
782 | struct v4l2_ctrl *ctrl, *next_ctrl; | 1114 | struct v4l2_ctrl *ctrl, *next_ctrl; |
1115 | struct v4l2_subscribed_event *sev, *next_sev; | ||
783 | 1116 | ||
784 | if (hdl == NULL || hdl->buckets == NULL) | 1117 | if (hdl == NULL || hdl->buckets == NULL) |
785 | return; | 1118 | return; |
@@ -793,6 +1126,8 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl) | |||
793 | /* Free all controls owned by the handler */ | 1126 | /* Free all controls owned by the handler */ |
794 | list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) { | 1127 | list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) { |
795 | list_del(&ctrl->node); | 1128 | list_del(&ctrl->node); |
1129 | list_for_each_entry_safe(sev, next_sev, &ctrl->ev_subs, node) | ||
1130 | list_del(&sev->node); | ||
796 | kfree(ctrl); | 1131 | kfree(ctrl); |
797 | } | 1132 | } |
798 | kfree(hdl->buckets); | 1133 | kfree(hdl->buckets); |
@@ -962,13 +1297,17 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, | |||
962 | 1297 | ||
963 | /* Sanity checks */ | 1298 | /* Sanity checks */ |
964 | if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE || | 1299 | if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE || |
965 | max < min || | ||
966 | (type == V4L2_CTRL_TYPE_INTEGER && step == 0) || | 1300 | (type == V4L2_CTRL_TYPE_INTEGER && step == 0) || |
1301 | (type == V4L2_CTRL_TYPE_BITMASK && max == 0) || | ||
967 | (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) || | 1302 | (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) || |
968 | (type == V4L2_CTRL_TYPE_STRING && max == 0)) { | 1303 | (type == V4L2_CTRL_TYPE_STRING && max == 0)) { |
969 | handler_set_err(hdl, -ERANGE); | 1304 | handler_set_err(hdl, -ERANGE); |
970 | return NULL; | 1305 | return NULL; |
971 | } | 1306 | } |
1307 | if (type != V4L2_CTRL_TYPE_BITMASK && max < min) { | ||
1308 | handler_set_err(hdl, -ERANGE); | ||
1309 | return NULL; | ||
1310 | } | ||
972 | if ((type == V4L2_CTRL_TYPE_INTEGER || | 1311 | if ((type == V4L2_CTRL_TYPE_INTEGER || |
973 | type == V4L2_CTRL_TYPE_MENU || | 1312 | type == V4L2_CTRL_TYPE_MENU || |
974 | type == V4L2_CTRL_TYPE_BOOLEAN) && | 1313 | type == V4L2_CTRL_TYPE_BOOLEAN) && |
@@ -976,6 +1315,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, | |||
976 | handler_set_err(hdl, -ERANGE); | 1315 | handler_set_err(hdl, -ERANGE); |
977 | return NULL; | 1316 | return NULL; |
978 | } | 1317 | } |
1318 | if (type == V4L2_CTRL_TYPE_BITMASK && ((def & ~max) || min || step)) { | ||
1319 | handler_set_err(hdl, -ERANGE); | ||
1320 | return NULL; | ||
1321 | } | ||
979 | 1322 | ||
980 | if (type == V4L2_CTRL_TYPE_BUTTON) | 1323 | if (type == V4L2_CTRL_TYPE_BUTTON) |
981 | flags |= V4L2_CTRL_FLAG_WRITE_ONLY; | 1324 | flags |= V4L2_CTRL_FLAG_WRITE_ONLY; |
@@ -991,6 +1334,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, | |||
991 | } | 1334 | } |
992 | 1335 | ||
993 | INIT_LIST_HEAD(&ctrl->node); | 1336 | INIT_LIST_HEAD(&ctrl->node); |
1337 | INIT_LIST_HEAD(&ctrl->ev_subs); | ||
994 | ctrl->handler = hdl; | 1338 | ctrl->handler = hdl; |
995 | ctrl->ops = ops; | 1339 | ctrl->ops = ops; |
996 | ctrl->id = id; | 1340 | ctrl->id = id; |
@@ -1132,6 +1476,9 @@ int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, | |||
1132 | /* Skip handler-private controls. */ | 1476 | /* Skip handler-private controls. */ |
1133 | if (ctrl->is_private) | 1477 | if (ctrl->is_private) |
1134 | continue; | 1478 | continue; |
1479 | /* And control classes */ | ||
1480 | if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) | ||
1481 | continue; | ||
1135 | ret = handler_new_ref(hdl, ctrl); | 1482 | ret = handler_new_ref(hdl, ctrl); |
1136 | if (ret) | 1483 | if (ret) |
1137 | break; | 1484 | break; |
@@ -1147,7 +1494,7 @@ void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls) | |||
1147 | int i; | 1494 | int i; |
1148 | 1495 | ||
1149 | /* The first control is the master control and it must not be NULL */ | 1496 | /* The first control is the master control and it must not be NULL */ |
1150 | BUG_ON(controls[0] == NULL); | 1497 | BUG_ON(ncontrols == 0 || controls[0] == NULL); |
1151 | 1498 | ||
1152 | for (i = 0; i < ncontrols; i++) { | 1499 | for (i = 0; i < ncontrols; i++) { |
1153 | if (controls[i]) { | 1500 | if (controls[i]) { |
@@ -1158,18 +1505,47 @@ void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls) | |||
1158 | } | 1505 | } |
1159 | EXPORT_SYMBOL(v4l2_ctrl_cluster); | 1506 | EXPORT_SYMBOL(v4l2_ctrl_cluster); |
1160 | 1507 | ||
1508 | void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls, | ||
1509 | u8 manual_val, bool set_volatile) | ||
1510 | { | ||
1511 | struct v4l2_ctrl *master = controls[0]; | ||
1512 | u32 flag; | ||
1513 | int i; | ||
1514 | |||
1515 | v4l2_ctrl_cluster(ncontrols, controls); | ||
1516 | WARN_ON(ncontrols <= 1); | ||
1517 | WARN_ON(manual_val < master->minimum || manual_val > master->maximum); | ||
1518 | master->is_auto = true; | ||
1519 | master->manual_mode_value = manual_val; | ||
1520 | master->flags |= V4L2_CTRL_FLAG_UPDATE; | ||
1521 | flag = is_cur_manual(master) ? 0 : V4L2_CTRL_FLAG_INACTIVE; | ||
1522 | |||
1523 | for (i = 1; i < ncontrols; i++) | ||
1524 | if (controls[i]) { | ||
1525 | controls[i]->is_volatile = set_volatile; | ||
1526 | controls[i]->flags |= flag; | ||
1527 | } | ||
1528 | } | ||
1529 | EXPORT_SYMBOL(v4l2_ctrl_auto_cluster); | ||
1530 | |||
1161 | /* Activate/deactivate a control. */ | 1531 | /* Activate/deactivate a control. */ |
1162 | void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active) | 1532 | void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active) |
1163 | { | 1533 | { |
1534 | /* invert since the actual flag is called 'inactive' */ | ||
1535 | bool inactive = !active; | ||
1536 | bool old; | ||
1537 | |||
1164 | if (ctrl == NULL) | 1538 | if (ctrl == NULL) |
1165 | return; | 1539 | return; |
1166 | 1540 | ||
1167 | if (!active) | 1541 | if (inactive) |
1168 | /* set V4L2_CTRL_FLAG_INACTIVE */ | 1542 | /* set V4L2_CTRL_FLAG_INACTIVE */ |
1169 | set_bit(4, &ctrl->flags); | 1543 | old = test_and_set_bit(4, &ctrl->flags); |
1170 | else | 1544 | else |
1171 | /* clear V4L2_CTRL_FLAG_INACTIVE */ | 1545 | /* clear V4L2_CTRL_FLAG_INACTIVE */ |
1172 | clear_bit(4, &ctrl->flags); | 1546 | old = test_and_clear_bit(4, &ctrl->flags); |
1547 | if (old != inactive) | ||
1548 | send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS); | ||
1173 | } | 1549 | } |
1174 | EXPORT_SYMBOL(v4l2_ctrl_activate); | 1550 | EXPORT_SYMBOL(v4l2_ctrl_activate); |
1175 | 1551 | ||
@@ -1181,15 +1557,21 @@ EXPORT_SYMBOL(v4l2_ctrl_activate); | |||
1181 | these controls. */ | 1557 | these controls. */ |
1182 | void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed) | 1558 | void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed) |
1183 | { | 1559 | { |
1560 | bool old; | ||
1561 | |||
1184 | if (ctrl == NULL) | 1562 | if (ctrl == NULL) |
1185 | return; | 1563 | return; |
1186 | 1564 | ||
1565 | v4l2_ctrl_lock(ctrl); | ||
1187 | if (grabbed) | 1566 | if (grabbed) |
1188 | /* set V4L2_CTRL_FLAG_GRABBED */ | 1567 | /* set V4L2_CTRL_FLAG_GRABBED */ |
1189 | set_bit(1, &ctrl->flags); | 1568 | old = test_and_set_bit(1, &ctrl->flags); |
1190 | else | 1569 | else |
1191 | /* clear V4L2_CTRL_FLAG_GRABBED */ | 1570 | /* clear V4L2_CTRL_FLAG_GRABBED */ |
1192 | clear_bit(1, &ctrl->flags); | 1571 | old = test_and_clear_bit(1, &ctrl->flags); |
1572 | if (old != grabbed) | ||
1573 | send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS); | ||
1574 | v4l2_ctrl_unlock(ctrl); | ||
1193 | } | 1575 | } |
1194 | EXPORT_SYMBOL(v4l2_ctrl_grab); | 1576 | EXPORT_SYMBOL(v4l2_ctrl_grab); |
1195 | 1577 | ||
@@ -1217,6 +1599,9 @@ static void log_ctrl(const struct v4l2_ctrl *ctrl, | |||
1217 | case V4L2_CTRL_TYPE_MENU: | 1599 | case V4L2_CTRL_TYPE_MENU: |
1218 | printk(KERN_CONT "%s", ctrl->qmenu[ctrl->cur.val]); | 1600 | printk(KERN_CONT "%s", ctrl->qmenu[ctrl->cur.val]); |
1219 | break; | 1601 | break; |
1602 | case V4L2_CTRL_TYPE_BITMASK: | ||
1603 | printk(KERN_CONT "0x%08x", ctrl->cur.val); | ||
1604 | break; | ||
1220 | case V4L2_CTRL_TYPE_INTEGER64: | 1605 | case V4L2_CTRL_TYPE_INTEGER64: |
1221 | printk(KERN_CONT "%lld", ctrl->cur.val64); | 1606 | printk(KERN_CONT "%lld", ctrl->cur.val64); |
1222 | break; | 1607 | break; |
@@ -1277,26 +1662,21 @@ int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl) | |||
1277 | int i; | 1662 | int i; |
1278 | 1663 | ||
1279 | /* Skip if this control was already handled by a cluster. */ | 1664 | /* Skip if this control was already handled by a cluster. */ |
1280 | if (ctrl->done) | 1665 | /* Skip button controls and read-only controls. */ |
1666 | if (ctrl->done || ctrl->type == V4L2_CTRL_TYPE_BUTTON || | ||
1667 | (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)) | ||
1281 | continue; | 1668 | continue; |
1282 | 1669 | ||
1283 | for (i = 0; i < master->ncontrols; i++) { | 1670 | for (i = 0; i < master->ncontrols; i++) { |
1284 | if (master->cluster[i]) { | 1671 | if (master->cluster[i]) { |
1285 | cur_to_new(master->cluster[i]); | 1672 | cur_to_new(master->cluster[i]); |
1286 | master->cluster[i]->is_new = 1; | 1673 | master->cluster[i]->is_new = 1; |
1674 | master->cluster[i]->done = true; | ||
1287 | } | 1675 | } |
1288 | } | 1676 | } |
1289 | 1677 | ret = call_op(master, s_ctrl); | |
1290 | /* Skip button controls and read-only controls. */ | ||
1291 | if (ctrl->type == V4L2_CTRL_TYPE_BUTTON || | ||
1292 | (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)) | ||
1293 | continue; | ||
1294 | ret = master->ops->s_ctrl(master); | ||
1295 | if (ret) | 1678 | if (ret) |
1296 | break; | 1679 | break; |
1297 | for (i = 0; i < master->ncontrols; i++) | ||
1298 | if (master->cluster[i]) | ||
1299 | master->cluster[i]->done = true; | ||
1300 | } | 1680 | } |
1301 | mutex_unlock(&hdl->lock); | 1681 | mutex_unlock(&hdl->lock); |
1302 | return ret; | 1682 | return ret; |
@@ -1447,18 +1827,19 @@ EXPORT_SYMBOL(v4l2_subdev_querymenu); | |||
1447 | Find the controls in the control array and do some basic checks. */ | 1827 | Find the controls in the control array and do some basic checks. */ |
1448 | static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, | 1828 | static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, |
1449 | struct v4l2_ext_controls *cs, | 1829 | struct v4l2_ext_controls *cs, |
1450 | struct ctrl_helper *helpers, | 1830 | struct v4l2_ctrl_helper *helpers) |
1451 | bool try) | ||
1452 | { | 1831 | { |
1832 | struct v4l2_ctrl_helper *h; | ||
1833 | bool have_clusters = false; | ||
1453 | u32 i; | 1834 | u32 i; |
1454 | 1835 | ||
1455 | for (i = 0; i < cs->count; i++) { | 1836 | for (i = 0, h = helpers; i < cs->count; i++, h++) { |
1456 | struct v4l2_ext_control *c = &cs->controls[i]; | 1837 | struct v4l2_ext_control *c = &cs->controls[i]; |
1838 | struct v4l2_ctrl_ref *ref; | ||
1457 | struct v4l2_ctrl *ctrl; | 1839 | struct v4l2_ctrl *ctrl; |
1458 | u32 id = c->id & V4L2_CTRL_ID_MASK; | 1840 | u32 id = c->id & V4L2_CTRL_ID_MASK; |
1459 | 1841 | ||
1460 | if (try) | 1842 | cs->error_idx = i; |
1461 | cs->error_idx = i; | ||
1462 | 1843 | ||
1463 | if (cs->ctrl_class && V4L2_CTRL_ID2CLASS(id) != cs->ctrl_class) | 1844 | if (cs->ctrl_class && V4L2_CTRL_ID2CLASS(id) != cs->ctrl_class) |
1464 | return -EINVAL; | 1845 | return -EINVAL; |
@@ -1467,53 +1848,59 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, | |||
1467 | extended controls */ | 1848 | extended controls */ |
1468 | if (id >= V4L2_CID_PRIVATE_BASE) | 1849 | if (id >= V4L2_CID_PRIVATE_BASE) |
1469 | return -EINVAL; | 1850 | return -EINVAL; |
1470 | ctrl = v4l2_ctrl_find(hdl, id); | 1851 | ref = find_ref_lock(hdl, id); |
1471 | if (ctrl == NULL) | 1852 | if (ref == NULL) |
1472 | return -EINVAL; | 1853 | return -EINVAL; |
1854 | ctrl = ref->ctrl; | ||
1473 | if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED) | 1855 | if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED) |
1474 | return -EINVAL; | 1856 | return -EINVAL; |
1475 | 1857 | ||
1476 | helpers[i].ctrl = ctrl; | 1858 | if (ctrl->cluster[0]->ncontrols > 1) |
1477 | helpers[i].handled = false; | 1859 | have_clusters = true; |
1860 | if (ctrl->cluster[0] != ctrl) | ||
1861 | ref = find_ref_lock(hdl, ctrl->cluster[0]->id); | ||
1862 | /* Store the ref to the master control of the cluster */ | ||
1863 | h->mref = ref; | ||
1864 | h->ctrl = ctrl; | ||
1865 | /* Initially set next to 0, meaning that there is no other | ||
1866 | control in this helper array belonging to the same | ||
1867 | cluster */ | ||
1868 | h->next = 0; | ||
1478 | } | 1869 | } |
1479 | return 0; | ||
1480 | } | ||
1481 | 1870 | ||
1482 | typedef int (*cluster_func)(struct v4l2_ext_control *c, | 1871 | /* We are done if there were no controls that belong to a multi- |
1483 | struct v4l2_ctrl *ctrl); | 1872 | control cluster. */ |
1873 | if (!have_clusters) | ||
1874 | return 0; | ||
1484 | 1875 | ||
1485 | /* Walk over all controls in v4l2_ext_controls belonging to the same cluster | 1876 | /* The code below figures out in O(n) time which controls in the list |
1486 | and call the provided function. */ | 1877 | belong to the same cluster. */ |
1487 | static int cluster_walk(unsigned from, | ||
1488 | struct v4l2_ext_controls *cs, | ||
1489 | struct ctrl_helper *helpers, | ||
1490 | cluster_func f) | ||
1491 | { | ||
1492 | struct v4l2_ctrl **cluster = helpers[from].ctrl->cluster; | ||
1493 | int ret = 0; | ||
1494 | int i; | ||
1495 | 1878 | ||
1496 | /* Find any controls from the same cluster and call the function */ | 1879 | /* This has to be done with the handler lock taken. */ |
1497 | for (i = from; !ret && i < cs->count; i++) { | 1880 | mutex_lock(&hdl->lock); |
1498 | struct v4l2_ctrl *ctrl = helpers[i].ctrl; | ||
1499 | 1881 | ||
1500 | if (!helpers[i].handled && ctrl->cluster == cluster) | 1882 | /* First zero the helper field in the master control references */ |
1501 | ret = f(&cs->controls[i], ctrl); | 1883 | for (i = 0; i < cs->count; i++) |
1884 | helpers[i].mref->helper = 0; | ||
1885 | for (i = 0, h = helpers; i < cs->count; i++, h++) { | ||
1886 | struct v4l2_ctrl_ref *mref = h->mref; | ||
1887 | |||
1888 | /* If the mref->helper is set, then it points to an earlier | ||
1889 | helper that belongs to the same cluster. */ | ||
1890 | if (mref->helper) { | ||
1891 | /* Set the next field of mref->helper to the current | ||
1892 | index: this means that that earlier helper now | ||
1893 | points to the next helper in the same cluster. */ | ||
1894 | mref->helper->next = i; | ||
1895 | /* mref should be set only for the first helper in the | ||
1896 | cluster, clear the others. */ | ||
1897 | h->mref = NULL; | ||
1898 | } | ||
1899 | /* Point the mref helper to the current helper struct. */ | ||
1900 | mref->helper = h; | ||
1502 | } | 1901 | } |
1503 | return ret; | 1902 | mutex_unlock(&hdl->lock); |
1504 | } | 1903 | return 0; |
1505 | |||
1506 | static void cluster_done(unsigned from, | ||
1507 | struct v4l2_ext_controls *cs, | ||
1508 | struct ctrl_helper *helpers) | ||
1509 | { | ||
1510 | struct v4l2_ctrl **cluster = helpers[from].ctrl->cluster; | ||
1511 | int i; | ||
1512 | |||
1513 | /* Find any controls from the same cluster and mark them as handled */ | ||
1514 | for (i = from; i < cs->count; i++) | ||
1515 | if (helpers[i].ctrl->cluster == cluster) | ||
1516 | helpers[i].handled = true; | ||
1517 | } | 1904 | } |
1518 | 1905 | ||
1519 | /* Handles the corner case where cs->count == 0. It checks whether the | 1906 | /* Handles the corner case where cs->count == 0. It checks whether the |
@@ -1531,10 +1918,10 @@ static int class_check(struct v4l2_ctrl_handler *hdl, u32 ctrl_class) | |||
1531 | /* Get extended controls. Allocates the helpers array if needed. */ | 1918 | /* Get extended controls. Allocates the helpers array if needed. */ |
1532 | int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) | 1919 | int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) |
1533 | { | 1920 | { |
1534 | struct ctrl_helper helper[4]; | 1921 | struct v4l2_ctrl_helper helper[4]; |
1535 | struct ctrl_helper *helpers = helper; | 1922 | struct v4l2_ctrl_helper *helpers = helper; |
1536 | int ret; | 1923 | int ret; |
1537 | int i; | 1924 | int i, j; |
1538 | 1925 | ||
1539 | cs->error_idx = cs->count; | 1926 | cs->error_idx = cs->count; |
1540 | cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class); | 1927 | cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class); |
@@ -1551,30 +1938,46 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs | |||
1551 | return -ENOMEM; | 1938 | return -ENOMEM; |
1552 | } | 1939 | } |
1553 | 1940 | ||
1554 | ret = prepare_ext_ctrls(hdl, cs, helpers, false); | 1941 | ret = prepare_ext_ctrls(hdl, cs, helpers); |
1942 | cs->error_idx = cs->count; | ||
1555 | 1943 | ||
1556 | for (i = 0; !ret && i < cs->count; i++) | 1944 | for (i = 0; !ret && i < cs->count; i++) |
1557 | if (helpers[i].ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) | 1945 | if (helpers[i].ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) |
1558 | ret = -EACCES; | 1946 | ret = -EACCES; |
1559 | 1947 | ||
1560 | for (i = 0; !ret && i < cs->count; i++) { | 1948 | for (i = 0; !ret && i < cs->count; i++) { |
1561 | struct v4l2_ctrl *ctrl = helpers[i].ctrl; | 1949 | int (*ctrl_to_user)(struct v4l2_ext_control *c, |
1562 | struct v4l2_ctrl *master = ctrl->cluster[0]; | 1950 | struct v4l2_ctrl *ctrl) = cur_to_user; |
1951 | struct v4l2_ctrl *master; | ||
1563 | 1952 | ||
1564 | if (helpers[i].handled) | 1953 | if (helpers[i].mref == NULL) |
1565 | continue; | 1954 | continue; |
1566 | 1955 | ||
1956 | master = helpers[i].mref->ctrl; | ||
1567 | cs->error_idx = i; | 1957 | cs->error_idx = i; |
1568 | 1958 | ||
1569 | v4l2_ctrl_lock(master); | 1959 | v4l2_ctrl_lock(master); |
1570 | /* g_volatile_ctrl will update the current control values */ | 1960 | |
1571 | if (ctrl->is_volatile && master->ops->g_volatile_ctrl) | 1961 | /* g_volatile_ctrl will update the new control values */ |
1572 | ret = master->ops->g_volatile_ctrl(master); | 1962 | if (has_op(master, g_volatile_ctrl) && !is_cur_manual(master)) { |
1573 | /* If OK, then copy the current control values to the caller */ | 1963 | for (j = 0; j < master->ncontrols; j++) |
1574 | if (!ret) | 1964 | cur_to_new(master->cluster[j]); |
1575 | ret = cluster_walk(i, cs, helpers, cur_to_user); | 1965 | ret = call_op(master, g_volatile_ctrl); |
1966 | ctrl_to_user = new_to_user; | ||
1967 | } | ||
1968 | /* If OK, then copy the current (for non-volatile controls) | ||
1969 | or the new (for volatile controls) control values to the | ||
1970 | caller */ | ||
1971 | if (!ret) { | ||
1972 | u32 idx = i; | ||
1973 | |||
1974 | do { | ||
1975 | ret = ctrl_to_user(cs->controls + idx, | ||
1976 | helpers[idx].ctrl); | ||
1977 | idx = helpers[idx].next; | ||
1978 | } while (!ret && idx); | ||
1979 | } | ||
1576 | v4l2_ctrl_unlock(master); | 1980 | v4l2_ctrl_unlock(master); |
1577 | cluster_done(i, cs, helpers); | ||
1578 | } | 1981 | } |
1579 | 1982 | ||
1580 | if (cs->count > ARRAY_SIZE(helper)) | 1983 | if (cs->count > ARRAY_SIZE(helper)) |
@@ -1594,15 +1997,21 @@ static int get_ctrl(struct v4l2_ctrl *ctrl, s32 *val) | |||
1594 | { | 1997 | { |
1595 | struct v4l2_ctrl *master = ctrl->cluster[0]; | 1998 | struct v4l2_ctrl *master = ctrl->cluster[0]; |
1596 | int ret = 0; | 1999 | int ret = 0; |
2000 | int i; | ||
1597 | 2001 | ||
1598 | if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) | 2002 | if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) |
1599 | return -EACCES; | 2003 | return -EACCES; |
1600 | 2004 | ||
1601 | v4l2_ctrl_lock(master); | 2005 | v4l2_ctrl_lock(master); |
1602 | /* g_volatile_ctrl will update the current control values */ | 2006 | /* g_volatile_ctrl will update the current control values */ |
1603 | if (ctrl->is_volatile && master->ops->g_volatile_ctrl) | 2007 | if (ctrl->is_volatile && !is_cur_manual(master)) { |
1604 | ret = master->ops->g_volatile_ctrl(master); | 2008 | for (i = 0; i < master->ncontrols; i++) |
1605 | *val = ctrl->cur.val; | 2009 | cur_to_new(master->cluster[i]); |
2010 | ret = call_op(master, g_volatile_ctrl); | ||
2011 | *val = ctrl->val; | ||
2012 | } else { | ||
2013 | *val = ctrl->cur.val; | ||
2014 | } | ||
1606 | v4l2_ctrl_unlock(master); | 2015 | v4l2_ctrl_unlock(master); |
1607 | return ret; | 2016 | return ret; |
1608 | } | 2017 | } |
@@ -1638,72 +2047,61 @@ EXPORT_SYMBOL(v4l2_ctrl_g_ctrl); | |||
1638 | /* Core function that calls try/s_ctrl and ensures that the new value is | 2047 | /* Core function that calls try/s_ctrl and ensures that the new value is |
1639 | copied to the current value on a set. | 2048 | copied to the current value on a set. |
1640 | Must be called with ctrl->handler->lock held. */ | 2049 | Must be called with ctrl->handler->lock held. */ |
1641 | static int try_or_set_control_cluster(struct v4l2_ctrl *master, bool set) | 2050 | static int try_or_set_cluster(struct v4l2_fh *fh, |
2051 | struct v4l2_ctrl *master, bool set) | ||
1642 | { | 2052 | { |
1643 | bool try = !set; | 2053 | bool update_flag; |
1644 | int ret = 0; | 2054 | int ret; |
1645 | int i; | 2055 | int i; |
1646 | 2056 | ||
1647 | /* Go through the cluster and either validate the new value or | 2057 | /* Go through the cluster and either validate the new value or |
1648 | (if no new value was set), copy the current value to the new | 2058 | (if no new value was set), copy the current value to the new |
1649 | value, ensuring a consistent view for the control ops when | 2059 | value, ensuring a consistent view for the control ops when |
1650 | called. */ | 2060 | called. */ |
1651 | for (i = 0; !ret && i < master->ncontrols; i++) { | 2061 | for (i = 0; i < master->ncontrols; i++) { |
1652 | struct v4l2_ctrl *ctrl = master->cluster[i]; | 2062 | struct v4l2_ctrl *ctrl = master->cluster[i]; |
1653 | 2063 | ||
1654 | if (ctrl == NULL) | 2064 | if (ctrl == NULL) |
1655 | continue; | 2065 | continue; |
1656 | 2066 | ||
1657 | if (ctrl->is_new) { | 2067 | if (!ctrl->is_new) { |
1658 | /* Double check this: it may have changed since the | 2068 | cur_to_new(ctrl); |
1659 | last check in try_or_set_ext_ctrls(). */ | ||
1660 | if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) | ||
1661 | return -EBUSY; | ||
1662 | |||
1663 | /* Validate if required */ | ||
1664 | if (!set) | ||
1665 | ret = validate_new(ctrl); | ||
1666 | continue; | 2069 | continue; |
1667 | } | 2070 | } |
1668 | /* No new value was set, so copy the current and force | 2071 | /* Check again: it may have changed since the |
1669 | a call to try_ctrl later, since the values for the cluster | 2072 | previous check in try_or_set_ext_ctrls(). */ |
1670 | may now have changed and the end result might be invalid. */ | 2073 | if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) |
1671 | try = true; | 2074 | return -EBUSY; |
1672 | cur_to_new(ctrl); | ||
1673 | } | 2075 | } |
1674 | 2076 | ||
1675 | /* For larger clusters you have to call try_ctrl again to | 2077 | ret = call_op(master, try_ctrl); |
1676 | verify that the controls are still valid after the | ||
1677 | 'cur_to_new' above. */ | ||
1678 | if (!ret && master->ops->try_ctrl && try) | ||
1679 | ret = master->ops->try_ctrl(master); | ||
1680 | 2078 | ||
1681 | /* Don't set if there is no change */ | 2079 | /* Don't set if there is no change */ |
1682 | if (!ret && set && cluster_changed(master)) { | 2080 | if (ret || !set || !cluster_changed(master)) |
1683 | ret = master->ops->s_ctrl(master); | 2081 | return ret; |
1684 | /* If OK, then make the new values permanent. */ | 2082 | ret = call_op(master, s_ctrl); |
1685 | if (!ret) | 2083 | if (ret) |
1686 | for (i = 0; i < master->ncontrols; i++) | 2084 | return ret; |
1687 | new_to_cur(master->cluster[i]); | 2085 | |
1688 | } | 2086 | /* If OK, then make the new values permanent. */ |
1689 | return ret; | 2087 | update_flag = is_cur_manual(master) != is_new_manual(master); |
2088 | for (i = 0; i < master->ncontrols; i++) | ||
2089 | new_to_cur(fh, master->cluster[i], update_flag && i > 0); | ||
2090 | return 0; | ||
1690 | } | 2091 | } |
1691 | 2092 | ||
1692 | /* Try or set controls. */ | 2093 | /* Validate controls. */ |
1693 | static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, | 2094 | static int validate_ctrls(struct v4l2_ext_controls *cs, |
1694 | struct v4l2_ext_controls *cs, | 2095 | struct v4l2_ctrl_helper *helpers, bool set) |
1695 | struct ctrl_helper *helpers, | ||
1696 | bool set) | ||
1697 | { | 2096 | { |
1698 | unsigned i, j; | 2097 | unsigned i; |
1699 | int ret = 0; | 2098 | int ret = 0; |
1700 | 2099 | ||
1701 | cs->error_idx = cs->count; | 2100 | cs->error_idx = cs->count; |
1702 | for (i = 0; i < cs->count; i++) { | 2101 | for (i = 0; i < cs->count; i++) { |
1703 | struct v4l2_ctrl *ctrl = helpers[i].ctrl; | 2102 | struct v4l2_ctrl *ctrl = helpers[i].ctrl; |
1704 | 2103 | ||
1705 | if (!set) | 2104 | cs->error_idx = i; |
1706 | cs->error_idx = i; | ||
1707 | 2105 | ||
1708 | if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) | 2106 | if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) |
1709 | return -EACCES; | 2107 | return -EACCES; |
@@ -1715,50 +2113,22 @@ static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, | |||
1715 | best-effort to avoid that. */ | 2113 | best-effort to avoid that. */ |
1716 | if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) | 2114 | if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) |
1717 | return -EBUSY; | 2115 | return -EBUSY; |
2116 | ret = validate_new(ctrl, &cs->controls[i]); | ||
2117 | if (ret) | ||
2118 | return ret; | ||
1718 | } | 2119 | } |
1719 | 2120 | return 0; | |
1720 | for (i = 0; !ret && i < cs->count; i++) { | ||
1721 | struct v4l2_ctrl *ctrl = helpers[i].ctrl; | ||
1722 | struct v4l2_ctrl *master = ctrl->cluster[0]; | ||
1723 | |||
1724 | cs->error_idx = i; | ||
1725 | |||
1726 | if (helpers[i].handled) | ||
1727 | continue; | ||
1728 | |||
1729 | v4l2_ctrl_lock(ctrl); | ||
1730 | |||
1731 | /* Reset the 'is_new' flags of the cluster */ | ||
1732 | for (j = 0; j < master->ncontrols; j++) | ||
1733 | if (master->cluster[j]) | ||
1734 | master->cluster[j]->is_new = 0; | ||
1735 | |||
1736 | /* Copy the new caller-supplied control values. | ||
1737 | user_to_new() sets 'is_new' to 1. */ | ||
1738 | ret = cluster_walk(i, cs, helpers, user_to_new); | ||
1739 | |||
1740 | if (!ret) | ||
1741 | ret = try_or_set_control_cluster(master, set); | ||
1742 | |||
1743 | /* Copy the new values back to userspace. */ | ||
1744 | if (!ret) | ||
1745 | ret = cluster_walk(i, cs, helpers, new_to_user); | ||
1746 | |||
1747 | v4l2_ctrl_unlock(ctrl); | ||
1748 | cluster_done(i, cs, helpers); | ||
1749 | } | ||
1750 | return ret; | ||
1751 | } | 2121 | } |
1752 | 2122 | ||
1753 | /* Try or try-and-set controls */ | 2123 | /* Try or try-and-set controls */ |
1754 | static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, | 2124 | static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, |
1755 | struct v4l2_ext_controls *cs, | 2125 | struct v4l2_ext_controls *cs, |
1756 | bool set) | 2126 | bool set) |
1757 | { | 2127 | { |
1758 | struct ctrl_helper helper[4]; | 2128 | struct v4l2_ctrl_helper helper[4]; |
1759 | struct ctrl_helper *helpers = helper; | 2129 | struct v4l2_ctrl_helper *helpers = helper; |
2130 | unsigned i, j; | ||
1760 | int ret; | 2131 | int ret; |
1761 | int i; | ||
1762 | 2132 | ||
1763 | cs->error_idx = cs->count; | 2133 | cs->error_idx = cs->count; |
1764 | cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class); | 2134 | cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class); |
@@ -1774,25 +2144,49 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, | |||
1774 | if (!helpers) | 2144 | if (!helpers) |
1775 | return -ENOMEM; | 2145 | return -ENOMEM; |
1776 | } | 2146 | } |
1777 | ret = prepare_ext_ctrls(hdl, cs, helpers, !set); | 2147 | ret = prepare_ext_ctrls(hdl, cs, helpers); |
1778 | if (ret) | 2148 | if (!ret) |
1779 | goto free; | 2149 | ret = validate_ctrls(cs, helpers, set); |
1780 | 2150 | if (ret && set) | |
1781 | /* First 'try' all controls and abort on error */ | ||
1782 | ret = try_or_set_ext_ctrls(hdl, cs, helpers, false); | ||
1783 | /* If this is a 'set' operation and the initial 'try' failed, | ||
1784 | then set error_idx to count to tell the application that no | ||
1785 | controls changed value yet. */ | ||
1786 | if (set) | ||
1787 | cs->error_idx = cs->count; | 2151 | cs->error_idx = cs->count; |
1788 | if (!ret && set) { | 2152 | for (i = 0; !ret && i < cs->count; i++) { |
1789 | /* Reset 'handled' state */ | 2153 | struct v4l2_ctrl *master; |
1790 | for (i = 0; i < cs->count; i++) | 2154 | u32 idx = i; |
1791 | helpers[i].handled = false; | 2155 | |
1792 | ret = try_or_set_ext_ctrls(hdl, cs, helpers, true); | 2156 | if (helpers[i].mref == NULL) |
2157 | continue; | ||
2158 | |||
2159 | cs->error_idx = i; | ||
2160 | master = helpers[i].mref->ctrl; | ||
2161 | v4l2_ctrl_lock(master); | ||
2162 | |||
2163 | /* Reset the 'is_new' flags of the cluster */ | ||
2164 | for (j = 0; j < master->ncontrols; j++) | ||
2165 | if (master->cluster[j]) | ||
2166 | master->cluster[j]->is_new = 0; | ||
2167 | |||
2168 | /* Copy the new caller-supplied control values. | ||
2169 | user_to_new() sets 'is_new' to 1. */ | ||
2170 | do { | ||
2171 | ret = user_to_new(cs->controls + idx, helpers[idx].ctrl); | ||
2172 | idx = helpers[idx].next; | ||
2173 | } while (!ret && idx); | ||
2174 | |||
2175 | if (!ret) | ||
2176 | ret = try_or_set_cluster(fh, master, set); | ||
2177 | |||
2178 | /* Copy the new values back to userspace. */ | ||
2179 | if (!ret) { | ||
2180 | idx = i; | ||
2181 | do { | ||
2182 | ret = new_to_user(cs->controls + idx, | ||
2183 | helpers[idx].ctrl); | ||
2184 | idx = helpers[idx].next; | ||
2185 | } while (!ret && idx); | ||
2186 | } | ||
2187 | v4l2_ctrl_unlock(master); | ||
1793 | } | 2188 | } |
1794 | 2189 | ||
1795 | free: | ||
1796 | if (cs->count > ARRAY_SIZE(helper)) | 2190 | if (cs->count > ARRAY_SIZE(helper)) |
1797 | kfree(helpers); | 2191 | kfree(helpers); |
1798 | return ret; | 2192 | return ret; |
@@ -1800,37 +2194,39 @@ free: | |||
1800 | 2194 | ||
1801 | int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) | 2195 | int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) |
1802 | { | 2196 | { |
1803 | return try_set_ext_ctrls(hdl, cs, false); | 2197 | return try_set_ext_ctrls(NULL, hdl, cs, false); |
1804 | } | 2198 | } |
1805 | EXPORT_SYMBOL(v4l2_try_ext_ctrls); | 2199 | EXPORT_SYMBOL(v4l2_try_ext_ctrls); |
1806 | 2200 | ||
1807 | int v4l2_s_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) | 2201 | int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, |
2202 | struct v4l2_ext_controls *cs) | ||
1808 | { | 2203 | { |
1809 | return try_set_ext_ctrls(hdl, cs, true); | 2204 | return try_set_ext_ctrls(fh, hdl, cs, true); |
1810 | } | 2205 | } |
1811 | EXPORT_SYMBOL(v4l2_s_ext_ctrls); | 2206 | EXPORT_SYMBOL(v4l2_s_ext_ctrls); |
1812 | 2207 | ||
1813 | int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs) | 2208 | int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs) |
1814 | { | 2209 | { |
1815 | return try_set_ext_ctrls(sd->ctrl_handler, cs, false); | 2210 | return try_set_ext_ctrls(NULL, sd->ctrl_handler, cs, false); |
1816 | } | 2211 | } |
1817 | EXPORT_SYMBOL(v4l2_subdev_try_ext_ctrls); | 2212 | EXPORT_SYMBOL(v4l2_subdev_try_ext_ctrls); |
1818 | 2213 | ||
1819 | int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs) | 2214 | int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs) |
1820 | { | 2215 | { |
1821 | return try_set_ext_ctrls(sd->ctrl_handler, cs, true); | 2216 | return try_set_ext_ctrls(NULL, sd->ctrl_handler, cs, true); |
1822 | } | 2217 | } |
1823 | EXPORT_SYMBOL(v4l2_subdev_s_ext_ctrls); | 2218 | EXPORT_SYMBOL(v4l2_subdev_s_ext_ctrls); |
1824 | 2219 | ||
1825 | /* Helper function for VIDIOC_S_CTRL compatibility */ | 2220 | /* Helper function for VIDIOC_S_CTRL compatibility */ |
1826 | static int set_ctrl(struct v4l2_ctrl *ctrl, s32 *val) | 2221 | static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, s32 *val) |
1827 | { | 2222 | { |
1828 | struct v4l2_ctrl *master = ctrl->cluster[0]; | 2223 | struct v4l2_ctrl *master = ctrl->cluster[0]; |
1829 | int ret; | 2224 | int ret; |
1830 | int i; | 2225 | int i; |
1831 | 2226 | ||
1832 | if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) | 2227 | ret = validate_new_int(ctrl, val); |
1833 | return -EACCES; | 2228 | if (ret) |
2229 | return ret; | ||
1834 | 2230 | ||
1835 | v4l2_ctrl_lock(ctrl); | 2231 | v4l2_ctrl_lock(ctrl); |
1836 | 2232 | ||
@@ -1841,28 +2237,30 @@ static int set_ctrl(struct v4l2_ctrl *ctrl, s32 *val) | |||
1841 | 2237 | ||
1842 | ctrl->val = *val; | 2238 | ctrl->val = *val; |
1843 | ctrl->is_new = 1; | 2239 | ctrl->is_new = 1; |
1844 | ret = try_or_set_control_cluster(master, false); | 2240 | ret = try_or_set_cluster(fh, master, true); |
1845 | if (!ret) | ||
1846 | ret = try_or_set_control_cluster(master, true); | ||
1847 | *val = ctrl->cur.val; | 2241 | *val = ctrl->cur.val; |
1848 | v4l2_ctrl_unlock(ctrl); | 2242 | v4l2_ctrl_unlock(ctrl); |
1849 | return ret; | 2243 | return ret; |
1850 | } | 2244 | } |
1851 | 2245 | ||
1852 | int v4l2_s_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control) | 2246 | int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, |
2247 | struct v4l2_control *control) | ||
1853 | { | 2248 | { |
1854 | struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); | 2249 | struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); |
1855 | 2250 | ||
1856 | if (ctrl == NULL || !type_is_int(ctrl)) | 2251 | if (ctrl == NULL || !type_is_int(ctrl)) |
1857 | return -EINVAL; | 2252 | return -EINVAL; |
1858 | 2253 | ||
1859 | return set_ctrl(ctrl, &control->value); | 2254 | if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) |
2255 | return -EACCES; | ||
2256 | |||
2257 | return set_ctrl(fh, ctrl, &control->value); | ||
1860 | } | 2258 | } |
1861 | EXPORT_SYMBOL(v4l2_s_ctrl); | 2259 | EXPORT_SYMBOL(v4l2_s_ctrl); |
1862 | 2260 | ||
1863 | int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *control) | 2261 | int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *control) |
1864 | { | 2262 | { |
1865 | return v4l2_s_ctrl(sd->ctrl_handler, control); | 2263 | return v4l2_s_ctrl(NULL, sd->ctrl_handler, control); |
1866 | } | 2264 | } |
1867 | EXPORT_SYMBOL(v4l2_subdev_s_ctrl); | 2265 | EXPORT_SYMBOL(v4l2_subdev_s_ctrl); |
1868 | 2266 | ||
@@ -1870,6 +2268,34 @@ int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val) | |||
1870 | { | 2268 | { |
1871 | /* It's a driver bug if this happens. */ | 2269 | /* It's a driver bug if this happens. */ |
1872 | WARN_ON(!type_is_int(ctrl)); | 2270 | WARN_ON(!type_is_int(ctrl)); |
1873 | return set_ctrl(ctrl, &val); | 2271 | return set_ctrl(NULL, ctrl, &val); |
1874 | } | 2272 | } |
1875 | EXPORT_SYMBOL(v4l2_ctrl_s_ctrl); | 2273 | EXPORT_SYMBOL(v4l2_ctrl_s_ctrl); |
2274 | |||
2275 | void v4l2_ctrl_add_event(struct v4l2_ctrl *ctrl, | ||
2276 | struct v4l2_subscribed_event *sev) | ||
2277 | { | ||
2278 | v4l2_ctrl_lock(ctrl); | ||
2279 | list_add_tail(&sev->node, &ctrl->ev_subs); | ||
2280 | if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS && | ||
2281 | (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) { | ||
2282 | struct v4l2_event ev; | ||
2283 | u32 changes = V4L2_EVENT_CTRL_CH_FLAGS; | ||
2284 | |||
2285 | if (!(ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)) | ||
2286 | changes |= V4L2_EVENT_CTRL_CH_VALUE; | ||
2287 | fill_event(&ev, ctrl, changes); | ||
2288 | v4l2_event_queue_fh(sev->fh, &ev); | ||
2289 | } | ||
2290 | v4l2_ctrl_unlock(ctrl); | ||
2291 | } | ||
2292 | EXPORT_SYMBOL(v4l2_ctrl_add_event); | ||
2293 | |||
2294 | void v4l2_ctrl_del_event(struct v4l2_ctrl *ctrl, | ||
2295 | struct v4l2_subscribed_event *sev) | ||
2296 | { | ||
2297 | v4l2_ctrl_lock(ctrl); | ||
2298 | list_del(&sev->node); | ||
2299 | v4l2_ctrl_unlock(ctrl); | ||
2300 | } | ||
2301 | EXPORT_SYMBOL(v4l2_ctrl_del_event); | ||