1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * V4L2 controls framework private header. 4 * 5 * Copyright (C) 2010-2021 Hans Verkuil <hverkuil-cisco@xs4all.nl> 6 */ 7 8 #ifndef _V4L2_CTRLS_PRIV_H_ 9 #define _V4L2_CTRLS_PRIV_H_ 10 11 #define dprintk(vdev, fmt, arg...) do { \ 12 if (!WARN_ON(!(vdev)) && ((vdev)->dev_debug & V4L2_DEV_DEBUG_CTRL)) \ 13 printk(KERN_DEBUG pr_fmt("%s: %s: " fmt), \ 14 __func__, video_device_node_name(vdev), ##arg); \ 15 } while (0) 16 17 #define has_op(master, op) \ 18 ((master)->ops && (master)->ops->op) 19 #define call_op(master, op) \ 20 (has_op(master, op) ? (master)->ops->op(master) : 0) 21 22 static inline u32 node2id(struct list_head *node) 23 { 24 return list_entry(node, struct v4l2_ctrl_ref, node)->ctrl->id; 25 } 26 27 /* 28 * Small helper function to determine if the autocluster is set to manual 29 * mode. 30 */ 31 static inline bool is_cur_manual(const struct v4l2_ctrl *master) 32 { 33 return master->is_auto && master->cur.val == master->manual_mode_value; 34 } 35 36 /* 37 * Small helper function to determine if the autocluster will be set to manual 38 * mode. 39 */ 40 static inline bool is_new_manual(const struct v4l2_ctrl *master) 41 { 42 return master->is_auto && master->val == master->manual_mode_value; 43 } 44 45 static inline u32 user_flags(const struct v4l2_ctrl *ctrl) 46 { 47 u32 flags = ctrl->flags; 48 49 if (ctrl->is_ptr) 50 flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD; 51 52 return flags; 53 } 54 55 /* v4l2-ctrls-core.c */ 56 void cur_to_new(struct v4l2_ctrl *ctrl); 57 void cur_to_req(struct v4l2_ctrl_ref *ref); 58 void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags); 59 void new_to_req(struct v4l2_ctrl_ref *ref); 60 void req_to_new(struct v4l2_ctrl_ref *ref); 61 void send_initial_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl); 62 void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes); 63 int validate_new(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr p_new); 64 int handler_new_ref(struct v4l2_ctrl_handler *hdl, 65 struct v4l2_ctrl *ctrl, 66 struct v4l2_ctrl_ref **ctrl_ref, 67 bool from_other_dev, bool allocate_req); 68 struct v4l2_ctrl_ref *find_ref(struct v4l2_ctrl_handler *hdl, u32 id); 69 struct v4l2_ctrl_ref *find_ref_lock(struct v4l2_ctrl_handler *hdl, u32 id); 70 int check_range(enum v4l2_ctrl_type type, 71 s64 min, s64 max, u64 step, s64 def); 72 void update_from_auto_cluster(struct v4l2_ctrl *master); 73 int try_or_set_cluster(struct v4l2_fh *fh, struct v4l2_ctrl *master, 74 bool set, u32 ch_flags); 75 76 /* v4l2-ctrls-api.c */ 77 int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *hdl, 78 struct v4l2_ext_controls *cs, 79 struct video_device *vdev); 80 int try_set_ext_ctrls_common(struct v4l2_fh *fh, 81 struct v4l2_ctrl_handler *hdl, 82 struct v4l2_ext_controls *cs, 83 struct video_device *vdev, bool set); 84 85 /* v4l2-ctrls-request.c */ 86 void v4l2_ctrl_handler_init_request(struct v4l2_ctrl_handler *hdl); 87 void v4l2_ctrl_handler_free_request(struct v4l2_ctrl_handler *hdl); 88 int v4l2_g_ext_ctrls_request(struct v4l2_ctrl_handler *hdl, struct video_device *vdev, 89 struct media_device *mdev, struct v4l2_ext_controls *cs); 90 int try_set_ext_ctrls_request(struct v4l2_fh *fh, 91 struct v4l2_ctrl_handler *hdl, 92 struct video_device *vdev, 93 struct media_device *mdev, 94 struct v4l2_ext_controls *cs, bool set); 95 96 #endif 97