Lines Matching full:ctrl
41 struct v4l2_ctrl *ctrl, in ptr_to_user() argument
46 if (ctrl->is_ptr && !ctrl->is_string) in ptr_to_user()
50 switch (ctrl->type) { in ptr_to_user()
54 c->size = ctrl->elem_size; in ptr_to_user()
70 static int cur_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) in cur_to_user() argument
72 return ptr_to_user(c, ctrl, ctrl->p_cur); in cur_to_user()
77 struct v4l2_ctrl *ctrl) in new_to_user() argument
79 return ptr_to_user(c, ctrl, ctrl->p_new); in new_to_user()
86 return ptr_to_user(c, ref->ctrl, ref->p_req); in req_to_user()
90 static int def_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) in def_to_user() argument
92 ctrl->type_ops->init(ctrl, 0, ctrl->p_new); in def_to_user()
94 return ptr_to_user(c, ctrl, ctrl->p_new); in def_to_user()
98 static int user_to_new(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) in user_to_new() argument
103 ctrl->is_new = 0; in user_to_new()
104 if (ctrl->is_dyn_array && in user_to_new()
105 c->size > ctrl->p_array_alloc_elems * ctrl->elem_size) { in user_to_new()
106 void *old = ctrl->p_array; in user_to_new()
111 memcpy(tmp, ctrl->p_new.p, ctrl->elems * ctrl->elem_size); in user_to_new()
112 memcpy(tmp + c->size, ctrl->p_cur.p, ctrl->elems * ctrl->elem_size); in user_to_new()
113 ctrl->p_new.p = tmp; in user_to_new()
114 ctrl->p_cur.p = tmp + c->size; in user_to_new()
115 ctrl->p_array = tmp; in user_to_new()
116 ctrl->p_array_alloc_elems = c->size / ctrl->elem_size; in user_to_new()
120 if (ctrl->is_ptr && !ctrl->is_string) { in user_to_new()
121 unsigned int elems = c->size / ctrl->elem_size; in user_to_new()
123 if (copy_from_user(ctrl->p_new.p, c->ptr, c->size)) in user_to_new()
125 ctrl->is_new = 1; in user_to_new()
126 if (ctrl->is_dyn_array) in user_to_new()
127 ctrl->new_elems = elems; in user_to_new()
128 else if (ctrl->is_array) in user_to_new()
129 ctrl->type_ops->init(ctrl, elems, ctrl->p_new); in user_to_new()
133 switch (ctrl->type) { in user_to_new()
135 *ctrl->p_new.p_s64 = c->value64; in user_to_new()
141 if (size > ctrl->maximum + 1) in user_to_new()
142 size = ctrl->maximum + 1; in user_to_new()
143 ret = copy_from_user(ctrl->p_new.p_char, c->string, size) ? -EFAULT : 0; in user_to_new()
145 char last = ctrl->p_new.p_char[size - 1]; in user_to_new()
147 ctrl->p_new.p_char[size - 1] = 0; in user_to_new()
149 * If the string was longer than ctrl->maximum, in user_to_new()
152 if (strlen(ctrl->p_new.p_char) == ctrl->maximum && last) in user_to_new()
157 *ctrl->p_new.p_s32 = c->value; in user_to_new()
160 ctrl->is_new = 1; in user_to_new()
225 struct v4l2_ctrl *ctrl; in prepare_ext_ctrls() local
255 ctrl = ref->ctrl; in prepare_ext_ctrls()
256 if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED) { in prepare_ext_ctrls()
261 if (ctrl->cluster[0]->ncontrols > 1) in prepare_ext_ctrls()
263 if (ctrl->cluster[0] != ctrl) in prepare_ext_ctrls()
264 ref = find_ref_lock(hdl, ctrl->cluster[0]->id); in prepare_ext_ctrls()
265 if (ctrl->is_dyn_array) { in prepare_ext_ctrls()
266 unsigned int max_size = ctrl->dims[0] * ctrl->elem_size; in prepare_ext_ctrls()
267 unsigned int tot_size = ctrl->elem_size; in prepare_ext_ctrls()
272 tot_size *= ctrl->elems; in prepare_ext_ctrls()
274 c->size = ctrl->elem_size * (c->size / ctrl->elem_size); in prepare_ext_ctrls()
289 } else if (ctrl->is_ptr && !ctrl->is_string) { in prepare_ext_ctrls()
290 unsigned int tot_size = ctrl->elems * ctrl->elem_size; in prepare_ext_ctrls()
416 if (helpers[i].ref->ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) in v4l2_g_ext_ctrls_common()
427 master = helpers[i].mref->ctrl; in v4l2_g_ext_ctrls_common()
464 ret = def_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
470 ret = new_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
472 ret = cur_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
495 static int validate_new(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr p_new) in validate_new() argument
497 return ctrl->type_ops->validate(ctrl, p_new); in validate_new()
511 struct v4l2_ctrl *ctrl = helpers[i].ref->ctrl; in validate_ctrls() local
516 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) { in validate_ctrls()
519 ctrl->id); in validate_ctrls()
530 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) { in validate_ctrls()
533 ctrl->id); in validate_ctrls()
540 if (ctrl->is_ptr) in validate_ctrls()
542 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in validate_ctrls()
546 ret = validate_new(ctrl, p_new); in validate_ctrls()
603 master = helpers[i].mref->ctrl; in try_set_ext_ctrls_common()
630 if (helpers[tmp_idx].ref->ctrl == master) in try_set_ext_ctrls_common()
647 struct v4l2_ctrl *ctrl = helpers[idx].ref->ctrl; in try_set_ext_ctrls_common() local
649 ret = user_to_new(cs->controls + idx, ctrl); in try_set_ext_ctrls_common()
650 if (!ret && ctrl->is_ptr) { in try_set_ext_ctrls_common()
651 ret = validate_new(ctrl, ctrl->p_new); in try_set_ext_ctrls_common()
655 v4l2_ctrl_get_name(ctrl->id), ret); in try_set_ext_ctrls_common()
677 helpers[idx].ref->ctrl); in try_set_ext_ctrls_common()
733 static int get_ctrl(struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c) in get_ctrl() argument
735 struct v4l2_ctrl *master = ctrl->cluster[0]; in get_ctrl()
743 if (!ctrl->is_int && ctrl->type != V4L2_CTRL_TYPE_INTEGER64) in get_ctrl()
746 if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) in get_ctrl()
751 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) { in get_ctrl()
755 new_to_user(c, ctrl); in get_ctrl()
757 cur_to_user(c, ctrl); in get_ctrl()
765 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_g_ctrl() local
769 if (!ctrl || !ctrl->is_int) in v4l2_g_ctrl()
771 ret = get_ctrl(ctrl, &c); in v4l2_g_ctrl()
778 static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags) in set_ctrl() argument
780 struct v4l2_ctrl *master = ctrl->cluster[0]; in set_ctrl()
789 ret = validate_new(ctrl, ctrl->p_new); in set_ctrl()
798 if (master->is_auto && master->has_volatiles && ctrl == master && in set_ctrl()
799 !is_cur_manual(master) && ctrl->val == master->manual_mode_value) in set_ctrl()
802 ctrl->is_new = 1; in set_ctrl()
807 static int set_ctrl_lock(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, in set_ctrl_lock() argument
812 v4l2_ctrl_lock(ctrl); in set_ctrl_lock()
813 user_to_new(c, ctrl); in set_ctrl_lock()
814 ret = set_ctrl(fh, ctrl, 0); in set_ctrl_lock()
816 cur_to_user(c, ctrl); in set_ctrl_lock()
817 v4l2_ctrl_unlock(ctrl); in set_ctrl_lock()
824 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_s_ctrl() local
828 if (!ctrl || !ctrl->is_int) in v4l2_s_ctrl()
831 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) in v4l2_s_ctrl()
835 ret = set_ctrl_lock(fh, ctrl, &c); in v4l2_s_ctrl()
845 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl) in v4l2_ctrl_g_ctrl() argument
850 if (WARN_ON(!ctrl->is_int)) in v4l2_ctrl_g_ctrl()
853 get_ctrl(ctrl, &c); in v4l2_ctrl_g_ctrl()
858 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl) in v4l2_ctrl_g_ctrl_int64() argument
863 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64)) in v4l2_ctrl_g_ctrl_int64()
866 get_ctrl(ctrl, &c); in v4l2_ctrl_g_ctrl_int64()
871 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val) in __v4l2_ctrl_s_ctrl() argument
873 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl()
876 if (WARN_ON(!ctrl->is_int)) in __v4l2_ctrl_s_ctrl()
878 ctrl->val = val; in __v4l2_ctrl_s_ctrl()
879 return set_ctrl(NULL, ctrl, 0); in __v4l2_ctrl_s_ctrl()
883 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val) in __v4l2_ctrl_s_ctrl_int64() argument
885 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_int64()
888 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64)) in __v4l2_ctrl_s_ctrl_int64()
890 *ctrl->p_new.p_s64 = val; in __v4l2_ctrl_s_ctrl_int64()
891 return set_ctrl(NULL, ctrl, 0); in __v4l2_ctrl_s_ctrl_int64()
895 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s) in __v4l2_ctrl_s_ctrl_string() argument
897 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_string()
900 if (WARN_ON(ctrl->type != V4L2_CTRL_TYPE_STRING)) in __v4l2_ctrl_s_ctrl_string()
902 strscpy(ctrl->p_new.p_char, s, ctrl->maximum + 1); in __v4l2_ctrl_s_ctrl_string()
903 return set_ctrl(NULL, ctrl, 0); in __v4l2_ctrl_s_ctrl_string()
907 int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl, in __v4l2_ctrl_s_ctrl_compound() argument
910 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_compound()
913 if (WARN_ON(ctrl->type != type)) in __v4l2_ctrl_s_ctrl_compound()
916 if (WARN_ON(ctrl->is_dyn_array)) in __v4l2_ctrl_s_ctrl_compound()
918 memcpy(ctrl->p_new.p, p, ctrl->elems * ctrl->elem_size); in __v4l2_ctrl_s_ctrl_compound()
919 return set_ctrl(NULL, ctrl, 0); in __v4l2_ctrl_s_ctrl_compound()
926 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, in __v4l2_ctrl_modify_range() argument
933 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_modify_range()
935 switch (ctrl->type) { in __v4l2_ctrl_modify_range()
945 if (ctrl->is_array) in __v4l2_ctrl_modify_range()
947 ret = check_range(ctrl->type, min, max, step, def); in __v4l2_ctrl_modify_range()
954 if (ctrl->minimum != min || ctrl->maximum != max || in __v4l2_ctrl_modify_range()
955 ctrl->step != step || ctrl->default_value != def) { in __v4l2_ctrl_modify_range()
957 ctrl->minimum = min; in __v4l2_ctrl_modify_range()
958 ctrl->maximum = max; in __v4l2_ctrl_modify_range()
959 ctrl->step = step; in __v4l2_ctrl_modify_range()
960 ctrl->default_value = def; in __v4l2_ctrl_modify_range()
962 cur_to_new(ctrl); in __v4l2_ctrl_modify_range()
963 if (validate_new(ctrl, ctrl->p_new)) { in __v4l2_ctrl_modify_range()
964 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in __v4l2_ctrl_modify_range()
965 *ctrl->p_new.p_s64 = def; in __v4l2_ctrl_modify_range()
967 *ctrl->p_new.p_s32 = def; in __v4l2_ctrl_modify_range()
970 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in __v4l2_ctrl_modify_range()
971 value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64; in __v4l2_ctrl_modify_range()
973 value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32; in __v4l2_ctrl_modify_range()
975 ret = set_ctrl(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE); in __v4l2_ctrl_modify_range()
977 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE); in __v4l2_ctrl_modify_range()
982 int __v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl, in __v4l2_ctrl_modify_dimensions() argument
989 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_modify_dimensions()
991 if (!ctrl->is_array || ctrl->is_dyn_array) in __v4l2_ctrl_modify_dimensions()
994 for (i = 0; i < ctrl->nr_of_dims; i++) in __v4l2_ctrl_modify_dimensions()
998 p_array = kvzalloc(2 * elems * ctrl->elem_size, GFP_KERNEL); in __v4l2_ctrl_modify_dimensions()
1001 kvfree(ctrl->p_array); in __v4l2_ctrl_modify_dimensions()
1002 ctrl->p_array_alloc_elems = elems; in __v4l2_ctrl_modify_dimensions()
1003 ctrl->elems = elems; in __v4l2_ctrl_modify_dimensions()
1004 ctrl->new_elems = elems; in __v4l2_ctrl_modify_dimensions()
1005 ctrl->p_array = p_array; in __v4l2_ctrl_modify_dimensions()
1006 ctrl->p_new.p = p_array; in __v4l2_ctrl_modify_dimensions()
1007 ctrl->p_cur.p = p_array + elems * ctrl->elem_size; in __v4l2_ctrl_modify_dimensions()
1008 for (i = 0; i < ctrl->nr_of_dims; i++) in __v4l2_ctrl_modify_dimensions()
1009 ctrl->dims[i] = dims[i]; in __v4l2_ctrl_modify_dimensions()
1010 ctrl->type_ops->init(ctrl, 0, ctrl->p_cur); in __v4l2_ctrl_modify_dimensions()
1011 cur_to_new(ctrl); in __v4l2_ctrl_modify_dimensions()
1012 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_VALUE | in __v4l2_ctrl_modify_dimensions()
1024 struct v4l2_ctrl *ctrl; in v4l2_query_ext_ctrl() local
1059 is_compound = ref->ctrl->is_array || in v4l2_query_ext_ctrl()
1060 ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; in v4l2_query_ext_ctrl()
1061 if (id < ref->ctrl->id && in v4l2_query_ext_ctrl()
1075 is_compound = ref->ctrl->is_array || in v4l2_query_ext_ctrl()
1076 ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; in v4l2_query_ext_ctrl()
1077 if (id < ref->ctrl->id && in v4l2_query_ext_ctrl()
1090 ctrl = ref->ctrl; in v4l2_query_ext_ctrl()
1095 qc->id = ctrl->id; in v4l2_query_ext_ctrl()
1096 strscpy(qc->name, ctrl->name, sizeof(qc->name)); in v4l2_query_ext_ctrl()
1097 qc->flags = user_flags(ctrl); in v4l2_query_ext_ctrl()
1098 qc->type = ctrl->type; in v4l2_query_ext_ctrl()
1099 qc->elem_size = ctrl->elem_size; in v4l2_query_ext_ctrl()
1100 qc->elems = ctrl->elems; in v4l2_query_ext_ctrl()
1101 qc->nr_of_dims = ctrl->nr_of_dims; in v4l2_query_ext_ctrl()
1102 memcpy(qc->dims, ctrl->dims, qc->nr_of_dims * sizeof(qc->dims[0])); in v4l2_query_ext_ctrl()
1103 qc->minimum = ctrl->minimum; in v4l2_query_ext_ctrl()
1104 qc->maximum = ctrl->maximum; in v4l2_query_ext_ctrl()
1105 qc->default_value = ctrl->default_value; in v4l2_query_ext_ctrl()
1106 if (ctrl->type == V4L2_CTRL_TYPE_MENU || in v4l2_query_ext_ctrl()
1107 ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU) in v4l2_query_ext_ctrl()
1110 qc->step = ctrl->step; in v4l2_query_ext_ctrl()
1155 struct v4l2_ctrl *ctrl; in v4l2_querymenu() local
1158 ctrl = v4l2_ctrl_find(hdl, qm->id); in v4l2_querymenu()
1159 if (!ctrl) in v4l2_querymenu()
1164 switch (ctrl->type) { in v4l2_querymenu()
1166 if (!ctrl->qmenu) in v4l2_querymenu()
1170 if (!ctrl->qmenu_int) in v4l2_querymenu()
1177 if (i < ctrl->minimum || i > ctrl->maximum) in v4l2_querymenu()
1181 if (ctrl->menu_skip_mask & (1ULL << i)) in v4l2_querymenu()
1184 if (ctrl->type == V4L2_CTRL_TYPE_MENU) { in v4l2_querymenu()
1185 if (!ctrl->qmenu[i] || ctrl->qmenu[i][0] == '\0') in v4l2_querymenu()
1187 strscpy(qm->name, ctrl->qmenu[i], sizeof(qm->name)); in v4l2_querymenu()
1189 qm->value = ctrl->qmenu_int[i]; in v4l2_querymenu()
1225 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); in v4l2_ctrl_add_event() local
1227 if (!ctrl) in v4l2_ctrl_add_event()
1230 v4l2_ctrl_lock(ctrl); in v4l2_ctrl_add_event()
1231 list_add_tail(&sev->node, &ctrl->ev_subs); in v4l2_ctrl_add_event()
1232 if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS && in v4l2_ctrl_add_event()
1234 send_initial_event(sev->fh, ctrl); in v4l2_ctrl_add_event()
1235 v4l2_ctrl_unlock(ctrl); in v4l2_ctrl_add_event()
1241 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); in v4l2_ctrl_del_event() local
1243 if (!ctrl) in v4l2_ctrl_del_event()
1246 v4l2_ctrl_lock(ctrl); in v4l2_ctrl_del_event()
1248 v4l2_ctrl_unlock(ctrl); in v4l2_ctrl_del_event()
1253 u32 old_changes = old->u.ctrl.changes; in v4l2_ctrl_replace()
1255 old->u.ctrl = new->u.ctrl; in v4l2_ctrl_replace()
1256 old->u.ctrl.changes |= old_changes; in v4l2_ctrl_replace()
1262 new->u.ctrl.changes |= old->u.ctrl.changes; in v4l2_ctrl_merge()