Lines Matching full:ctrl
19 static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl, in fill_event() argument
24 ev->id = ctrl->id; in fill_event()
25 ev->u.ctrl.changes = changes; in fill_event()
26 ev->u.ctrl.type = ctrl->type; in fill_event()
27 ev->u.ctrl.flags = user_flags(ctrl); in fill_event()
28 if (ctrl->is_ptr) in fill_event()
29 ev->u.ctrl.value64 = 0; in fill_event()
31 ev->u.ctrl.value64 = *ctrl->p_cur.p_s64; in fill_event()
32 ev->u.ctrl.minimum = ctrl->minimum; in fill_event()
33 ev->u.ctrl.maximum = ctrl->maximum; in fill_event()
34 if (ctrl->type == V4L2_CTRL_TYPE_MENU in fill_event()
35 || ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU) in fill_event()
36 ev->u.ctrl.step = 1; in fill_event()
38 ev->u.ctrl.step = ctrl->step; in fill_event()
39 ev->u.ctrl.default_value = ctrl->default_value; in fill_event()
42 void send_initial_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl) in send_initial_event() argument
47 if (!(ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)) in send_initial_event()
49 fill_event(&ev, ctrl, changes); in send_initial_event()
53 void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes) in send_event() argument
58 if (list_empty(&ctrl->ev_subs)) in send_event()
60 fill_event(&ev, ctrl, changes); in send_event()
62 list_for_each_entry(sev, &ctrl->ev_subs, node) in send_event()
68 static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx, in std_equal() argument
72 switch (ctrl->type) { in std_equal()
76 idx *= ctrl->elem_size; in std_equal()
88 if (ctrl->is_int) in std_equal()
90 idx *= ctrl->elem_size; in std_equal()
92 ctrl->elem_size); in std_equal()
108 static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx, in std_init_compound() argument
116 void *p = ptr.p + idx * ctrl->elem_size; in std_init_compound()
118 if (ctrl->p_def.p_const) in std_init_compound()
119 memcpy(p, ctrl->p_def.p_const, ctrl->elem_size); in std_init_compound()
121 memset(p, 0, ctrl->elem_size); in std_init_compound()
123 switch ((u32)ctrl->type) { in std_init_compound()
166 static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, in std_init() argument
169 switch (ctrl->type) { in std_init()
171 idx *= ctrl->elem_size; in std_init()
172 memset(ptr.p_char + idx, ' ', ctrl->minimum); in std_init()
173 ptr.p_char[idx + ctrl->minimum] = '\0'; in std_init()
176 ptr.p_s64[idx] = ctrl->default_value; in std_init()
183 ptr.p_s32[idx] = ctrl->default_value; in std_init()
190 ptr.p_u8[idx] = ctrl->default_value; in std_init()
193 ptr.p_u16[idx] = ctrl->default_value; in std_init()
196 ptr.p_u32[idx] = ctrl->default_value; in std_init()
199 std_init_compound(ctrl, idx, ptr); in std_init()
204 static void std_log(const struct v4l2_ctrl *ctrl) in std_log() argument
206 union v4l2_ctrl_ptr ptr = ctrl->p_cur; in std_log()
208 if (ctrl->is_array) { in std_log()
211 for (i = 0; i < ctrl->nr_of_dims; i++) in std_log()
212 pr_cont("[%u]", ctrl->dims[i]); in std_log()
216 switch (ctrl->type) { in std_log()
224 pr_cont("%s", ctrl->qmenu[*ptr.p_s32]); in std_log()
227 pr_cont("%lld", ctrl->qmenu_int[*ptr.p_s32]); in std_log()
287 pr_cont("unknown type %d", ctrl->type); in std_log()
297 #define ROUND_TO_RANGE(val, offset_type, ctrl) \ argument
300 if ((ctrl)->maximum >= 0 && \
301 val >= (ctrl)->maximum - (s32)((ctrl)->step / 2)) \
302 val = (ctrl)->maximum; \
304 val += (s32)((ctrl)->step / 2); \
306 (ctrl)->minimum, (ctrl)->maximum); \
307 offset = (val) - (ctrl)->minimum; \
308 offset = (ctrl)->step * (offset / (u32)(ctrl)->step); \
309 val = (ctrl)->minimum + offset; \
324 static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx, in std_validate_compound() argument
342 void *p = ptr.p + idx * ctrl->elem_size; in std_validate_compound()
345 switch ((u32)ctrl->type) { in std_validate_compound()
703 static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx, in std_validate() argument
710 switch ((u32)ctrl->type) { in std_validate()
712 return ROUND_TO_RANGE(ptr.p_s32[idx], u32, ctrl); in std_validate()
719 if (ctrl->maximum >= 0 && val >= ctrl->maximum - (s64)(ctrl->step / 2)) in std_validate()
720 val = ctrl->maximum; in std_validate()
722 val += (s64)(ctrl->step / 2); in std_validate()
723 val = clamp_t(s64, val, ctrl->minimum, ctrl->maximum); in std_validate()
724 offset = val - ctrl->minimum; in std_validate()
725 do_div(offset, ctrl->step); in std_validate()
726 ptr.p_s64[idx] = ctrl->minimum + offset * ctrl->step; in std_validate()
729 return ROUND_TO_RANGE(ptr.p_u8[idx], u8, ctrl); in std_validate()
731 return ROUND_TO_RANGE(ptr.p_u16[idx], u16, ctrl); in std_validate()
733 return ROUND_TO_RANGE(ptr.p_u32[idx], u32, ctrl); in std_validate()
741 if (ptr.p_s32[idx] < ctrl->minimum || ptr.p_s32[idx] > ctrl->maximum) in std_validate()
744 (ctrl->menu_skip_mask & BIT_ULL(ptr.p_s32[idx]))) in std_validate()
746 if (ctrl->type == V4L2_CTRL_TYPE_MENU && in std_validate()
747 ctrl->qmenu[ptr.p_s32[idx]][0] == '\0') in std_validate()
752 ptr.p_s32[idx] &= ctrl->maximum; in std_validate()
761 idx *= ctrl->elem_size; in std_validate()
763 if (len < ctrl->minimum) in std_validate()
765 if ((len - (u32)ctrl->minimum) % (u32)ctrl->step) in std_validate()
770 return std_validate_compound(ctrl, idx, ptr); in std_validate()
781 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv) in v4l2_ctrl_notify() argument
783 if (!ctrl) in v4l2_ctrl_notify()
786 ctrl->call_notify = 0; in v4l2_ctrl_notify()
789 if (WARN_ON(ctrl->handler->notify && ctrl->handler->notify != notify)) in v4l2_ctrl_notify()
791 ctrl->handler->notify = notify; in v4l2_ctrl_notify()
792 ctrl->handler->notify_priv = priv; in v4l2_ctrl_notify()
793 ctrl->call_notify = 1; in v4l2_ctrl_notify()
798 static void ptr_to_ptr(struct v4l2_ctrl *ctrl, in ptr_to_ptr() argument
801 if (ctrl == NULL) in ptr_to_ptr()
803 memcpy(to.p, from.p_const, ctrl->elems * ctrl->elem_size); in ptr_to_ptr()
807 void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags) in new_to_cur() argument
811 if (ctrl == NULL) in new_to_cur()
815 changed = ctrl->has_changed; in new_to_cur()
817 ptr_to_ptr(ctrl, ctrl->p_new, ctrl->p_cur); in new_to_cur()
821 ctrl->flags &= in new_to_cur()
823 if (!is_cur_manual(ctrl->cluster[0])) { in new_to_cur()
824 ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; in new_to_cur()
825 if (ctrl->cluster[0]->has_volatiles) in new_to_cur()
826 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; in new_to_cur()
833 if (!ctrl->is_new) in new_to_cur()
835 send_event(fh, ctrl, in new_to_cur()
837 if (ctrl->call_notify && changed && ctrl->handler->notify) in new_to_cur()
838 ctrl->handler->notify(ctrl, ctrl->handler->notify_priv); in new_to_cur()
843 void cur_to_new(struct v4l2_ctrl *ctrl) in cur_to_new() argument
845 if (ctrl == NULL) in cur_to_new()
847 ptr_to_ptr(ctrl, ctrl->p_cur, ctrl->p_new); in cur_to_new()
855 ptr_to_ptr(ref->ctrl, ref->ctrl->p_new, ref->p_req); in new_to_req()
864 ptr_to_ptr(ref->ctrl, ref->ctrl->p_cur, ref->p_req); in cur_to_req()
874 ptr_to_ptr(ref->ctrl, ref->p_req, ref->ctrl->p_new); in req_to_new()
876 ptr_to_ptr(ref->ctrl, ref->ctrl->p_cur, ref->ctrl->p_new); in req_to_new()
919 int validate_new(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr p_new) in validate_new() argument
924 for (idx = 0; !err && idx < ctrl->elems; idx++) in validate_new()
925 err = ctrl->type_ops->validate(ctrl, idx, p_new); in validate_new()
961 struct v4l2_ctrl *ctrl, *next_ctrl; in v4l2_ctrl_handler_free() local
976 list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) { in v4l2_ctrl_handler_free()
977 list_del(&ctrl->node); in v4l2_ctrl_handler_free()
978 list_for_each_entry_safe(sev, next_sev, &ctrl->ev_subs, node) in v4l2_ctrl_handler_free()
980 kvfree(ctrl); in v4l2_ctrl_handler_free()
1006 if (V4L2_CTRL_ID2WHICH(ref->ctrl->id) == V4L2_CTRL_CLASS_USER && in find_private_ref()
1007 V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) { in find_private_ref()
1008 if (!ref->ctrl->is_int) in find_private_ref()
1032 if (hdl->cached && hdl->cached->ctrl->id == id) in find_ref()
1037 while (ref && ref->ctrl->id != id) in find_ref()
1063 return ref ? ref->ctrl : NULL; in v4l2_ctrl_find()
1069 struct v4l2_ctrl *ctrl, in handler_new_ref() argument
1075 u32 id = ctrl->id; in handler_new_ref()
1087 if (ctrl->type < V4L2_CTRL_COMPOUND_TYPES && in handler_new_ref()
1096 size_extra_req = ctrl->elems * ctrl->elem_size; in handler_new_ref()
1100 new_ref->ctrl = ctrl; in handler_new_ref()
1120 if (ref->ctrl->id < id) in handler_new_ref()
1123 if (ref->ctrl->id == id) { in handler_new_ref()
1137 if (ctrl->handler == hdl) { in handler_new_ref()
1139 * new_ref->ctrl is basically a cluster array with one in handler_new_ref()
1143 ctrl->cluster = &new_ref->ctrl; in handler_new_ref()
1144 ctrl->ncontrols = 1; in handler_new_ref()
1163 struct v4l2_ctrl *ctrl; in v4l2_ctrl_new() local
1297 ctrl = kvzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL); in v4l2_ctrl_new()
1298 if (ctrl == NULL) { in v4l2_ctrl_new()
1303 INIT_LIST_HEAD(&ctrl->node); in v4l2_ctrl_new()
1304 INIT_LIST_HEAD(&ctrl->ev_subs); in v4l2_ctrl_new()
1305 ctrl->handler = hdl; in v4l2_ctrl_new()
1306 ctrl->ops = ops; in v4l2_ctrl_new()
1307 ctrl->type_ops = type_ops ? type_ops : &std_type_ops; in v4l2_ctrl_new()
1308 ctrl->id = id; in v4l2_ctrl_new()
1309 ctrl->name = name; in v4l2_ctrl_new()
1310 ctrl->type = type; in v4l2_ctrl_new()
1311 ctrl->flags = flags; in v4l2_ctrl_new()
1312 ctrl->minimum = min; in v4l2_ctrl_new()
1313 ctrl->maximum = max; in v4l2_ctrl_new()
1314 ctrl->step = step; in v4l2_ctrl_new()
1315 ctrl->default_value = def; in v4l2_ctrl_new()
1316 ctrl->is_string = !is_array && type == V4L2_CTRL_TYPE_STRING; in v4l2_ctrl_new()
1317 ctrl->is_ptr = is_array || type >= V4L2_CTRL_COMPOUND_TYPES || ctrl->is_string; in v4l2_ctrl_new()
1318 ctrl->is_int = !ctrl->is_ptr && type != V4L2_CTRL_TYPE_INTEGER64; in v4l2_ctrl_new()
1319 ctrl->is_array = is_array; in v4l2_ctrl_new()
1320 ctrl->elems = elems; in v4l2_ctrl_new()
1321 ctrl->nr_of_dims = nr_of_dims; in v4l2_ctrl_new()
1323 memcpy(ctrl->dims, dims, nr_of_dims * sizeof(dims[0])); in v4l2_ctrl_new()
1324 ctrl->elem_size = elem_size; in v4l2_ctrl_new()
1326 ctrl->qmenu = qmenu; in v4l2_ctrl_new()
1328 ctrl->qmenu_int = qmenu_int; in v4l2_ctrl_new()
1329 ctrl->priv = priv; in v4l2_ctrl_new()
1330 ctrl->cur.val = ctrl->val = def; in v4l2_ctrl_new()
1331 data = &ctrl[1]; in v4l2_ctrl_new()
1333 if (!ctrl->is_int) { in v4l2_ctrl_new()
1334 ctrl->p_new.p = data; in v4l2_ctrl_new()
1335 ctrl->p_cur.p = data + tot_ctrl_size; in v4l2_ctrl_new()
1337 ctrl->p_new.p = &ctrl->val; in v4l2_ctrl_new()
1338 ctrl->p_cur.p = &ctrl->cur.val; in v4l2_ctrl_new()
1342 ctrl->p_def.p = ctrl->p_cur.p + tot_ctrl_size; in v4l2_ctrl_new()
1343 memcpy(ctrl->p_def.p, p_def.p_const, elem_size); in v4l2_ctrl_new()
1347 ctrl->type_ops->init(ctrl, idx, ctrl->p_cur); in v4l2_ctrl_new()
1348 ctrl->type_ops->init(ctrl, idx, ctrl->p_new); in v4l2_ctrl_new()
1351 if (handler_new_ref(hdl, ctrl, NULL, false, false)) { in v4l2_ctrl_new()
1352 kvfree(ctrl); in v4l2_ctrl_new()
1356 list_add_tail(&ctrl->node, &hdl->ctrls); in v4l2_ctrl_new()
1358 return ctrl; in v4l2_ctrl_new()
1365 struct v4l2_ctrl *ctrl; in v4l2_ctrl_new_custom() local
1393 ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->type_ops, cfg->id, name, in v4l2_ctrl_new_custom()
1398 if (ctrl) in v4l2_ctrl_new_custom()
1399 ctrl->is_private = cfg->is_private; in v4l2_ctrl_new_custom()
1400 return ctrl; in v4l2_ctrl_new_custom()
1540 bool (*filter)(const struct v4l2_ctrl *ctrl), in v4l2_ctrl_add_handler() argument
1553 struct v4l2_ctrl *ctrl = ref->ctrl; in v4l2_ctrl_add_handler() local
1556 if (ctrl->is_private) in v4l2_ctrl_add_handler()
1559 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) in v4l2_ctrl_add_handler()
1562 if (filter && !filter(ctrl)) in v4l2_ctrl_add_handler()
1564 ret = handler_new_ref(hdl, ctrl, NULL, from_other_dev, false); in v4l2_ctrl_add_handler()
1573 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl) in v4l2_ctrl_radio_filter() argument
1575 if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_TX) in v4l2_ctrl_radio_filter()
1577 if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_RX) in v4l2_ctrl_radio_filter()
1579 switch (ctrl->id) { in v4l2_ctrl_radio_filter()
1669 struct v4l2_ctrl *ctrl = master->cluster[i]; in cluster_changed() local
1672 if (!ctrl) in cluster_changed()
1675 if (ctrl->flags & V4L2_CTRL_FLAG_EXECUTE_ON_WRITE) { in cluster_changed()
1684 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) { in cluster_changed()
1685 ctrl->has_changed = false; in cluster_changed()
1689 for (idx = 0; !ctrl_changed && idx < ctrl->elems; idx++) in cluster_changed()
1690 ctrl_changed = !ctrl->type_ops->equal(ctrl, idx, in cluster_changed()
1691 ctrl->p_cur, ctrl->p_new); in cluster_changed()
1692 ctrl->has_changed = ctrl_changed; in cluster_changed()
1693 changed |= ctrl->has_changed; in cluster_changed()
1701 * Must be called with ctrl->handler->lock held.
1717 struct v4l2_ctrl *ctrl = master->cluster[i]; in try_or_set_cluster() local
1719 if (!ctrl) in try_or_set_cluster()
1722 if (!ctrl->is_new) { in try_or_set_cluster()
1723 cur_to_new(ctrl); in try_or_set_cluster()
1730 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) in try_or_set_cluster()
1765 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active) in v4l2_ctrl_activate() argument
1771 if (ctrl == NULL) in v4l2_ctrl_activate()
1776 old = test_and_set_bit(4, &ctrl->flags); in v4l2_ctrl_activate()
1779 old = test_and_clear_bit(4, &ctrl->flags); in v4l2_ctrl_activate()
1781 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS); in v4l2_ctrl_activate()
1785 void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed) in __v4l2_ctrl_grab() argument
1789 if (ctrl == NULL) in __v4l2_ctrl_grab()
1792 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_grab()
1796 old = test_and_set_bit(1, &ctrl->flags); in __v4l2_ctrl_grab()
1799 old = test_and_clear_bit(1, &ctrl->flags); in __v4l2_ctrl_grab()
1801 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS); in __v4l2_ctrl_grab()
1808 struct v4l2_ctrl *ctrl; in __v4l2_ctrl_handler_setup() local
1816 list_for_each_entry(ctrl, &hdl->ctrls, node) in __v4l2_ctrl_handler_setup()
1817 ctrl->done = false; in __v4l2_ctrl_handler_setup()
1819 list_for_each_entry(ctrl, &hdl->ctrls, node) { in __v4l2_ctrl_handler_setup()
1820 struct v4l2_ctrl *master = ctrl->cluster[0]; in __v4l2_ctrl_handler_setup()
1825 if (ctrl->done || ctrl->type == V4L2_CTRL_TYPE_BUTTON || in __v4l2_ctrl_handler_setup()
1826 (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)) in __v4l2_ctrl_handler_setup()
1861 static void log_ctrl(const struct v4l2_ctrl *ctrl, in log_ctrl() argument
1864 if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY)) in log_ctrl()
1866 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) in log_ctrl()
1869 pr_info("%s%s%s: ", prefix, colon, ctrl->name); in log_ctrl()
1871 ctrl->type_ops->log(ctrl); in log_ctrl()
1873 if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE | in log_ctrl()
1876 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) in log_ctrl()
1878 if (ctrl->flags & V4L2_CTRL_FLAG_GRABBED) in log_ctrl()
1880 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) in log_ctrl()
1890 struct v4l2_ctrl *ctrl; in v4l2_ctrl_handler_log_status() local
1902 list_for_each_entry(ctrl, &hdl->ctrls, node) in v4l2_ctrl_handler_log_status()
1903 if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED)) in v4l2_ctrl_handler_log_status()
1904 log_ctrl(ctrl, prefix, colon); in v4l2_ctrl_handler_log_status()