xref: /linux/drivers/media/v4l2-core/v4l2-ctrls-priv.h (revision 8c994eff8fcfe8ecb1f1dbebed25b4d7bb75be12)
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 int 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 handler_new_ref(struct v4l2_ctrl_handler *hdl,
64 		    struct v4l2_ctrl *ctrl,
65 		    struct v4l2_ctrl_ref **ctrl_ref,
66 		    bool from_other_dev, bool allocate_req);
67 struct v4l2_ctrl_ref *find_ref(struct v4l2_ctrl_handler *hdl, u32 id);
68 struct v4l2_ctrl_ref *find_ref_lock(struct v4l2_ctrl_handler *hdl, u32 id);
69 int check_range(enum v4l2_ctrl_type type,
70 		s64 min, s64 max, u64 step, s64 def);
71 void update_from_auto_cluster(struct v4l2_ctrl *master);
72 int try_or_set_cluster(struct v4l2_fh *fh, struct v4l2_ctrl *master,
73 		       bool set, u32 ch_flags);
74 
75 /* v4l2-ctrls-api.c */
76 int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *hdl,
77 			    struct v4l2_ext_controls *cs,
78 			    struct video_device *vdev);
79 int try_set_ext_ctrls_common(struct v4l2_fh *fh,
80 			     struct v4l2_ctrl_handler *hdl,
81 			     struct v4l2_ext_controls *cs,
82 			     struct video_device *vdev, bool set);
83 
84 /* v4l2-ctrls-request.c */
85 void v4l2_ctrl_handler_init_request(struct v4l2_ctrl_handler *hdl);
86 void v4l2_ctrl_handler_free_request(struct v4l2_ctrl_handler *hdl);
87 int v4l2_g_ext_ctrls_request(struct v4l2_ctrl_handler *hdl, struct video_device *vdev,
88 			     struct media_device *mdev, struct v4l2_ext_controls *cs);
89 int try_set_ext_ctrls_request(struct v4l2_fh *fh,
90 			      struct v4l2_ctrl_handler *hdl,
91 			      struct video_device *vdev,
92 			      struct media_device *mdev,
93 			      struct v4l2_ext_controls *cs, bool set);
94 
95 #endif
96