Lines Matching full:ctrl

19 static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl,
24 ev->id = ctrl->id;
25 ev->u.ctrl.changes = changes;
26 ev->u.ctrl.type = ctrl->type;
27 ev->u.ctrl.flags = user_flags(ctrl);
28 if (ctrl->is_ptr)
29 ev->u.ctrl.value64 = 0;
31 ev->u.ctrl.value64 = *ctrl->p_cur.p_s64;
32 ev->u.ctrl.minimum = ctrl->minimum;
33 ev->u.ctrl.maximum = ctrl->maximum;
34 if (ctrl->type == V4L2_CTRL_TYPE_MENU
35 || ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU)
36 ev->u.ctrl.step = 1;
38 ev->u.ctrl.step = ctrl->step;
39 ev->u.ctrl.default_value = ctrl->default_value;
42 void send_initial_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl)
47 if (!(ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY))
49 fill_event(&ev, ctrl, changes);
53 void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes)
58 if (list_empty(&ctrl->ev_subs))
60 fill_event(&ev, ctrl, changes);
62 list_for_each_entry(sev, &ctrl->ev_subs, node)
68 bool v4l2_ctrl_type_op_equal(const struct v4l2_ctrl *ctrl,
73 switch (ctrl->type) {
77 for (i = 0; i < ctrl->elems; i++) {
78 unsigned int idx = i * ctrl->elem_size;
87 ctrl->elems * ctrl->elem_size);
104 static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx,
115 void *p = ptr.p + idx * ctrl->elem_size;
117 if (ctrl->p_def.p_const)
118 memcpy(p, ctrl->p_def.p_const, ctrl->elem_size);
120 memset(p, 0, ctrl->elem_size);
122 switch ((u32)ctrl->type) {
185 static void std_min_compound(const struct v4l2_ctrl *ctrl, u32 idx,
188 void *p = ptr.p + idx * ctrl->elem_size;
190 if (ctrl->p_min.p_const)
191 memcpy(p, ctrl->p_min.p_const, ctrl->elem_size);
193 memset(p, 0, ctrl->elem_size);
196 static void std_max_compound(const struct v4l2_ctrl *ctrl, u32 idx,
199 void *p = ptr.p + idx * ctrl->elem_size;
201 if (ctrl->p_max.p_const)
202 memcpy(p, ctrl->p_max.p_const, ctrl->elem_size);
204 memset(p, 0, ctrl->elem_size);
207 static void __v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx,
211 u32 tot_elems = ctrl->elems;
217 value = ctrl->default_value;
220 value = ctrl->maximum;
223 value = ctrl->minimum;
229 switch (ctrl->type) {
232 value = ctrl->minimum;
235 unsigned int offset = i * ctrl->elem_size;
288 std_init_compound(ctrl, i, ptr);
291 std_max_compound(ctrl, i, ptr);
294 std_min_compound(ctrl, i, ptr);
302 void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx,
305 __v4l2_ctrl_type_op_init(ctrl, from_idx, V4L2_CTRL_WHICH_DEF_VAL, ptr);
309 static void v4l2_ctrl_type_op_minimum(const struct v4l2_ctrl *ctrl,
312 __v4l2_ctrl_type_op_init(ctrl, from_idx, V4L2_CTRL_WHICH_MIN_VAL, ptr);
315 static void v4l2_ctrl_type_op_maximum(const struct v4l2_ctrl *ctrl,
318 __v4l2_ctrl_type_op_init(ctrl, from_idx, V4L2_CTRL_WHICH_MAX_VAL, ptr);
321 void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl)
323 union v4l2_ctrl_ptr ptr = ctrl->p_cur;
325 if (ctrl->is_array) {
328 for (i = 0; i < ctrl->nr_of_dims; i++)
329 pr_cont("[%u]", ctrl->dims[i]);
333 switch (ctrl->type) {
341 pr_cont("%s", ctrl->qmenu[*ptr.p_s32]);
344 pr_cont("%lld", ctrl->qmenu_int[*ptr.p_s32]);
445 pr_cont("unknown type %d", ctrl->type);
456 #define ROUND_TO_RANGE(val, offset_type, ctrl) \
459 if ((ctrl)->maximum >= 0 && \
460 val >= (ctrl)->maximum - (s32)((ctrl)->step / 2)) \
461 val = (ctrl)->maximum; \
463 val += (s32)((ctrl)->step / 2); \
465 (ctrl)->minimum, (ctrl)->maximum); \
466 offset = (val) - (ctrl)->minimum; \
467 offset = (ctrl)->step * (offset / (u32)(ctrl)->step); \
468 val = (ctrl)->minimum + offset; \
871 static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
889 void *p = ptr.p + idx * ctrl->elem_size;
892 switch ((u32)ctrl->type) {
1259 static int std_validate_elem(const struct v4l2_ctrl *ctrl, u32 idx,
1266 switch ((u32)ctrl->type) {
1268 return ROUND_TO_RANGE(ptr.p_s32[idx], u32, ctrl);
1275 if (ctrl->maximum >= 0 && val >= ctrl->maximum - (s64)(ctrl->step / 2))
1276 val = ctrl->maximum;
1278 val += (s64)(ctrl->step / 2);
1279 val = clamp_t(s64, val, ctrl->minimum, ctrl->maximum);
1280 offset = val - ctrl->minimum;
1281 do_div(offset, ctrl->step);
1282 ptr.p_s64[idx] = ctrl->minimum + offset * ctrl->step;
1285 return ROUND_TO_RANGE(ptr.p_u8[idx], u8, ctrl);
1287 return ROUND_TO_RANGE(ptr.p_u16[idx], u16, ctrl);
1289 return ROUND_TO_RANGE(ptr.p_u32[idx], u32, ctrl);
1297 if (ptr.p_s32[idx] < ctrl->minimum || ptr.p_s32[idx] > ctrl->maximum)
1300 (ctrl->menu_skip_mask & BIT_ULL(ptr.p_s32[idx])))
1302 if (ctrl->type == V4L2_CTRL_TYPE_MENU &&
1303 ctrl->qmenu[ptr.p_s32[idx]][0] == '\0')
1308 ptr.p_s32[idx] &= ctrl->maximum;
1317 idx *= ctrl->elem_size;
1319 if (len < ctrl->minimum)
1321 if ((len - (u32)ctrl->minimum) % (u32)ctrl->step)
1326 return std_validate_compound(ctrl, idx, ptr);
1330 int v4l2_ctrl_type_op_validate(const struct v4l2_ctrl *ctrl,
1336 switch ((u32)ctrl->type) {
1338 if (ctrl->maximum == 0xff && ctrl->minimum == 0 && ctrl->step == 1)
1342 if (ctrl->maximum == 0xffff && ctrl->minimum == 0 && ctrl->step == 1)
1346 if (ctrl->maximum == 0xffffffff && ctrl->minimum == 0 && ctrl->step == 1)
1352 memset(ptr.p_s32, 0, ctrl->new_elems * sizeof(s32));
1356 for (i = 0; !ret && i < ctrl->new_elems; i++)
1357 ret = std_validate_elem(ctrl, i, ptr);
1371 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv)
1373 if (!ctrl)
1376 ctrl->call_notify = 0;
1379 if (WARN_ON(ctrl->handler->notify && ctrl->handler->notify != notify))
1381 ctrl->handler->notify = notify;
1382 ctrl->handler->notify_priv = priv;
1383 ctrl->call_notify = 1;
1388 static void ptr_to_ptr(struct v4l2_ctrl *ctrl,
1392 if (ctrl == NULL)
1394 memcpy(to.p, from.p_const, elems * ctrl->elem_size);
1398 void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags)
1402 if (ctrl == NULL)
1406 changed = ctrl->has_changed;
1408 if (ctrl->is_dyn_array)
1409 ctrl->elems = ctrl->new_elems;
1410 ptr_to_ptr(ctrl, ctrl->p_new, ctrl->p_cur, ctrl->elems);
1415 ctrl->flags &=
1417 if (!is_cur_manual(ctrl->cluster[0])) {
1418 ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
1419 if (ctrl->cluster[0]->has_volatiles)
1420 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
1427 if (!ctrl->is_new)
1429 send_event(fh, ctrl,
1431 if (ctrl->call_notify && changed && ctrl->handler->notify)
1432 ctrl->handler->notify(ctrl, ctrl->handler->notify_priv);
1437 void cur_to_new(struct v4l2_ctrl *ctrl)
1439 if (ctrl == NULL)
1441 if (ctrl->is_dyn_array)
1442 ctrl->new_elems = ctrl->elems;
1443 ptr_to_ptr(ctrl, ctrl->p_cur, ctrl->p_new, ctrl->new_elems);
1452 if (ref->ctrl->is_dyn_array &&
1456 tmp = kvmalloc(elems * ref->ctrl->elem_size, GFP_KERNEL);
1472 struct v4l2_ctrl *ctrl;
1477 ctrl = ref->ctrl;
1478 if (ctrl->is_array && !req_alloc_array(ref, ctrl->new_elems))
1481 ref->p_req_elems = ctrl->new_elems;
1482 ptr_to_ptr(ctrl, ctrl->p_new, ref->p_req, ref->p_req_elems);
1489 struct v4l2_ctrl *ctrl;
1494 ctrl = ref->ctrl;
1495 if (ctrl->is_array && !req_alloc_array(ref, ctrl->elems))
1498 ref->p_req_elems = ctrl->elems;
1499 ptr_to_ptr(ctrl, ctrl->p_cur, ref->p_req, ctrl->elems);
1506 struct v4l2_ctrl *ctrl;
1511 ctrl = ref->ctrl;
1518 if (ctrl->is_dyn_array)
1519 ctrl->new_elems = ctrl->elems;
1520 ptr_to_ptr(ctrl, ctrl->p_cur, ctrl->p_new, ctrl->new_elems);
1525 if (!ctrl->is_array) {
1526 ptr_to_ptr(ctrl, ref->p_req, ctrl->p_new, ctrl->new_elems);
1534 if (!ctrl->is_dyn_array &&
1535 ref->p_req_elems != ctrl->p_array_alloc_elems)
1540 * elements in ctrl->p_array. If so, attempt to realloc ctrl->p_array.
1545 if (ref->p_req_elems > ctrl->p_array_alloc_elems) {
1546 unsigned int sz = ref->p_req_elems * ctrl->elem_size;
1547 void *old = ctrl->p_array;
1552 memcpy(tmp, ctrl->p_new.p, ctrl->elems * ctrl->elem_size);
1553 memcpy(tmp + sz, ctrl->p_cur.p, ctrl->elems * ctrl->elem_size);
1554 ctrl->p_new.p = tmp;
1555 ctrl->p_cur.p = tmp + sz;
1556 ctrl->p_array = tmp;
1557 ctrl->p_array_alloc_elems = ref->p_req_elems;
1561 ctrl->new_elems = ref->p_req_elems;
1562 ptr_to_ptr(ctrl, ref->p_req, ctrl->p_new, ctrl->new_elems);
1637 struct v4l2_ctrl *ctrl, *next_ctrl;
1657 list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) {
1658 list_del(&ctrl->node);
1659 list_for_each_entry_safe(sev, next_sev, &ctrl->ev_subs, node)
1661 kvfree(ctrl->p_array);
1662 kvfree(ctrl);
1689 if (V4L2_CTRL_ID2WHICH(ref->ctrl->id) == V4L2_CTRL_CLASS_USER &&
1690 V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) {
1691 if (!ref->ctrl->is_int)
1715 if (hdl->cached && hdl->cached->ctrl->id == id)
1720 while (ref && ref->ctrl->id != id)
1746 return ref ? ref->ctrl : NULL;
1752 struct v4l2_ctrl *ctrl,
1758 u32 id = ctrl->id;
1770 if (ctrl->type < V4L2_CTRL_COMPOUND_TYPES &&
1778 if (allocate_req && !ctrl->is_array)
1779 size_extra_req = ctrl->elems * ctrl->elem_size;
1783 new_ref->ctrl = ctrl;
1803 if (ref->ctrl->id < id)
1806 if (ref->ctrl->id == id) {
1820 if (ctrl->handler == hdl) {
1822 * new_ref->ctrl is basically a cluster array with one
1826 ctrl->cluster = &new_ref->ctrl;
1827 ctrl->ncontrols = 1;
1849 struct v4l2_ctrl *ctrl;
2031 ctrl = kvzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL);
2032 if (ctrl == NULL) {
2037 INIT_LIST_HEAD(&ctrl->node);
2038 INIT_LIST_HEAD(&ctrl->ev_subs);
2039 ctrl->handler = hdl;
2040 ctrl->ops = ops;
2041 ctrl->type_ops = type_ops ? type_ops : &std_type_ops;
2042 ctrl->id = id;
2043 ctrl->name = name;
2044 ctrl->type = type;
2045 ctrl->flags = flags;
2046 ctrl->minimum = min;
2047 ctrl->maximum = max;
2048 ctrl->step = step;
2049 ctrl->default_value = def;
2050 ctrl->is_string = !is_array && type == V4L2_CTRL_TYPE_STRING;
2051 ctrl->is_ptr = is_array || type >= V4L2_CTRL_COMPOUND_TYPES || ctrl->is_string;
2052 ctrl->is_int = !ctrl->is_ptr && type != V4L2_CTRL_TYPE_INTEGER64;
2053 ctrl->is_array = is_array;
2054 ctrl->is_dyn_array = !!(flags & V4L2_CTRL_FLAG_DYNAMIC_ARRAY);
2055 ctrl->elems = elems;
2056 ctrl->new_elems = elems;
2057 ctrl->nr_of_dims = nr_of_dims;
2059 memcpy(ctrl->dims, dims, nr_of_dims * sizeof(dims[0]));
2060 ctrl->elem_size = elem_size;
2062 ctrl->qmenu = qmenu;
2064 ctrl->qmenu_int = qmenu_int;
2065 ctrl->priv = priv;
2066 ctrl->cur.val = ctrl->val = def;
2067 data = &ctrl[1];
2069 if (ctrl->is_array) {
2070 ctrl->p_array_alloc_elems = elems;
2071 ctrl->p_array = kvzalloc(2 * elems * elem_size, GFP_KERNEL);
2072 if (!ctrl->p_array) {
2073 kvfree(ctrl);
2076 data = ctrl->p_array;
2079 if (!ctrl->is_int) {
2080 ctrl->p_new.p = data;
2081 ctrl->p_cur.p = data + tot_ctrl_size;
2083 ctrl->p_new.p = &ctrl->val;
2084 ctrl->p_cur.p = &ctrl->cur.val;
2088 if (ctrl->is_array)
2089 ctrl->p_def.p = &ctrl[1];
2091 ctrl->p_def.p = ctrl->p_cur.p + tot_ctrl_size;
2092 memcpy(ctrl->p_def.p, p_def.p_const, elem_size);
2096 void *ptr = ctrl->p_def.p;
2100 ctrl->p_min.p = ptr;
2101 memcpy(ctrl->p_min.p, p_min.p_const, elem_size);
2106 ctrl->p_max.p = ptr;
2107 memcpy(ctrl->p_max.p, p_max.p_const, elem_size);
2111 ctrl->type_ops->init(ctrl, 0, ctrl->p_cur);
2112 cur_to_new(ctrl);
2114 if (handler_new_ref(hdl, ctrl, NULL, false, false)) {
2115 kvfree(ctrl->p_array);
2116 kvfree(ctrl);
2120 list_add_tail(&ctrl->node, &hdl->ctrls);
2122 return ctrl;
2129 struct v4l2_ctrl *ctrl;
2157 ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->type_ops, cfg->id, name,
2163 if (ctrl)
2164 ctrl->is_private = cfg->is_private;
2165 return ctrl;
2311 bool (*filter)(const struct v4l2_ctrl *ctrl),
2324 struct v4l2_ctrl *ctrl = ref->ctrl;
2327 if (ctrl->is_private)
2330 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
2333 if (filter && !filter(ctrl))
2335 ret = handler_new_ref(hdl, ctrl, NULL, from_other_dev, false);
2344 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl)
2346 if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_TX)
2348 if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_RX)
2350 switch (ctrl->id) {
2439 struct v4l2_ctrl *ctrl = master->cluster[i];
2442 if (!ctrl)
2445 if (ctrl->flags & V4L2_CTRL_FLAG_EXECUTE_ON_WRITE) {
2454 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) {
2455 ctrl->has_changed = false;
2459 if (ctrl->elems != ctrl->new_elems)
2462 ctrl_changed = !ctrl->type_ops->equal(ctrl,
2463 ctrl->p_cur, ctrl->p_new);
2464 ctrl->has_changed = ctrl_changed;
2465 changed |= ctrl->has_changed;
2473 * Must be called with ctrl->handler->lock held.
2489 struct v4l2_ctrl *ctrl = master->cluster[i];
2491 if (!ctrl)
2494 if (!ctrl->is_new) {
2495 cur_to_new(ctrl);
2502 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED))
2537 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active)
2543 if (ctrl == NULL)
2548 old = test_and_set_bit(4, &ctrl->flags);
2551 old = test_and_clear_bit(4, &ctrl->flags);
2553 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS);
2557 void __v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
2561 if (ctrl == NULL)
2564 lockdep_assert_held(ctrl->handler->lock);
2568 old = test_and_set_bit(1, &ctrl->flags);
2571 old = test_and_clear_bit(1, &ctrl->flags);
2573 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS);
2580 struct v4l2_ctrl *ctrl;
2588 list_for_each_entry(ctrl, &hdl->ctrls, node)
2589 ctrl->done = false;
2591 list_for_each_entry(ctrl, &hdl->ctrls, node) {
2592 struct v4l2_ctrl *master = ctrl->cluster[0];
2597 if (ctrl->done || ctrl->type == V4L2_CTRL_TYPE_BUTTON ||
2598 (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY))
2633 static void log_ctrl(const struct v4l2_ctrl *ctrl,
2636 if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY))
2638 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
2641 pr_info("%s%s%s: ", prefix, colon, ctrl->name);
2643 ctrl->type_ops->log(ctrl);
2645 if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE |
2648 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
2650 if (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)
2652 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE)
2662 struct v4l2_ctrl *ctrl;
2674 list_for_each_entry(ctrl, &hdl->ctrls, node)
2675 if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED))
2676 log_ctrl(ctrl, prefix, colon);