Lines Matching refs:ctrl

40 	struct v4l2_ctrl *ctrl;
829 static bool type_is_int(const struct v4l2_ctrl *ctrl)
831 switch (ctrl->type) {
841 static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl, u32 changes)
845 ev->id = ctrl->id;
846 ev->u.ctrl.changes = changes;
847 ev->u.ctrl.type = ctrl->type;
848 ev->u.ctrl.flags = ctrl->flags;
849 if (ctrl->type == V4L2_CTRL_TYPE_STRING)
850 ev->u.ctrl.value64 = 0;
852 ev->u.ctrl.value64 = ctrl->cur.val64;
853 ev->u.ctrl.minimum = ctrl->minimum;
854 ev->u.ctrl.maximum = ctrl->maximum;
855 if (ctrl->type == V4L2_CTRL_TYPE_MENU)
856 ev->u.ctrl.step = 1;
858 ev->u.ctrl.step = ctrl->step;
859 ev->u.ctrl.default_value = ctrl->default_value;
862 static void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes)
867 if (list_empty(&ctrl->ev_subs))
869 fill_event(&ev, ctrl, changes);
871 list_for_each_entry(sev, &ctrl->ev_subs, node)
879 struct v4l2_ctrl *ctrl)
883 switch (ctrl->type) {
885 len = strlen(ctrl->cur.string);
890 return copy_to_user(c->string, ctrl->cur.string,
893 c->value64 = ctrl->cur.val64;
896 c->value = ctrl->cur.val;
904 struct v4l2_ctrl *ctrl)
909 ctrl->is_new = 1;
910 switch (ctrl->type) {
912 ctrl->val64 = c->value64;
918 if (size > ctrl->maximum + 1)
919 size = ctrl->maximum + 1;
920 ret = copy_from_user(ctrl->string, c->string, size);
922 char last = ctrl->string[size - 1];
924 ctrl->string[size - 1] = 0;
925 /* If the string was longer than ctrl->maximum,
927 if (strlen(ctrl->string) == ctrl->maximum && last)
932 ctrl->val = c->value;
940 struct v4l2_ctrl *ctrl)
944 switch (ctrl->type) {
946 len = strlen(ctrl->string);
948 c->size = ctrl->maximum + 1;
951 return copy_to_user(c->string, ctrl->string,
954 c->value64 = ctrl->val64;
957 c->value = ctrl->val;
964 static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
969 if (ctrl == NULL)
971 switch (ctrl->type) {
977 changed = strcmp(ctrl->string, ctrl->cur.string);
978 strcpy(ctrl->cur.string, ctrl->string);
981 changed = ctrl->val64 != ctrl->cur.val64;
982 ctrl->cur.val64 = ctrl->val64;
985 changed = ctrl->val != ctrl->cur.val;
986 ctrl->cur.val = ctrl->val;
991 ctrl->flags &=
993 if (!is_cur_manual(ctrl->cluster[0])) {
994 ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
995 if (ctrl->cluster[0]->has_volatiles)
996 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
1003 if (!ctrl->is_new)
1005 send_event(fh, ctrl,
1012 static void cur_to_new(struct v4l2_ctrl *ctrl)
1014 if (ctrl == NULL)
1016 switch (ctrl->type) {
1019 strcpy(ctrl->string, ctrl->cur.string);
1022 ctrl->val64 = ctrl->cur.val64;
1025 ctrl->val = ctrl->cur.val;
1038 struct v4l2_ctrl *ctrl = master->cluster[i];
1040 if (ctrl == NULL)
1042 switch (ctrl->type) {
1048 diff = strcmp(ctrl->string, ctrl->cur.string);
1051 diff = ctrl->val64 != ctrl->cur.val64;
1054 diff = ctrl->val != ctrl->cur.val;
1062 static int validate_new_int(const struct v4l2_ctrl *ctrl, s32 *pval)
1067 switch (ctrl->type) {
1070 val += ctrl->step / 2;
1071 if (val < ctrl->minimum)
1072 val = ctrl->minimum;
1073 if (val > ctrl->maximum)
1074 val = ctrl->maximum;
1075 offset = val - ctrl->minimum;
1076 offset = ctrl->step * (offset / ctrl->step);
1077 val = ctrl->minimum + offset;
1086 if (val < ctrl->minimum || val > ctrl->maximum)
1088 if (ctrl->qmenu[val][0] == '\0' ||
1089 (ctrl->menu_skip_mask & (1 << val)))
1094 *pval &= ctrl->maximum;
1108 static int validate_new(const struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c)
1113 switch (ctrl->type) {
1120 return validate_new_int(ctrl, &c->value);
1127 if (len < ctrl->minimum)
1129 if ((len - ctrl->minimum) % ctrl->step)
1140 return list_entry(node, struct v4l2_ctrl_ref, node)->ctrl->id;
1170 struct v4l2_ctrl *ctrl, *next_ctrl;
1183 list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) {
1184 list_del(&ctrl->node);
1185 list_for_each_entry_safe(sev, next_sev, &ctrl->ev_subs, node)
1187 kfree(ctrl);
1212 if (V4L2_CTRL_ID2CLASS(ref->ctrl->id) == V4L2_CTRL_CLASS_USER &&
1213 V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) {
1214 if (!type_is_int(ref->ctrl))
1238 if (hdl->cached && hdl->cached->ctrl->id == id)
1243 while (ref && ref->ctrl->id != id)
1270 return ref ? ref->ctrl : NULL;
1276 struct v4l2_ctrl *ctrl)
1280 u32 id = ctrl->id;
1295 new_ref->ctrl = ctrl;
1296 if (ctrl->handler == hdl) {
1298 new_ref->ctrl is basically a cluster array with one
1301 ctrl->cluster = &new_ref->ctrl;
1302 ctrl->ncontrols = 1;
1320 if (ref->ctrl->id < id)
1323 if (ref->ctrl->id == id) {
1348 struct v4l2_ctrl *ctrl;
1386 ctrl = kzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL);
1387 if (ctrl == NULL) {
1392 INIT_LIST_HEAD(&ctrl->node);
1393 INIT_LIST_HEAD(&ctrl->ev_subs);
1394 ctrl->handler = hdl;
1395 ctrl->ops = ops;
1396 ctrl->id = id;
1397 ctrl->name = name;
1398 ctrl->type = type;
1399 ctrl->flags = flags;
1400 ctrl->minimum = min;
1401 ctrl->maximum = max;
1402 ctrl->step = step;
1403 ctrl->qmenu = qmenu;
1404 ctrl->priv = priv;
1405 ctrl->cur.val = ctrl->val = ctrl->default_value = def;
1407 if (ctrl->type == V4L2_CTRL_TYPE_STRING) {
1408 ctrl->cur.string = (char *)&ctrl[1] + sz_extra - (max + 1);
1409 ctrl->string = (char *)&ctrl[1] + sz_extra - 2 * (max + 1);
1410 if (ctrl->minimum)
1411 memset(ctrl->cur.string, ' ', ctrl->minimum);
1413 if (handler_new_ref(hdl, ctrl)) {
1414 kfree(ctrl);
1418 list_add_tail(&ctrl->node, &hdl->ctrls);
1420 return ctrl;
1427 struct v4l2_ctrl *ctrl;
1449 ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->id, name,
1453 if (ctrl)
1454 ctrl->is_private = cfg->is_private;
1455 return ctrl;
1502 struct v4l2_ctrl *ctrl)
1506 if (ctrl == NULL) {
1510 if (ctrl->handler == hdl)
1511 return ctrl;
1512 return handler_new_ref(hdl, ctrl) ? NULL : ctrl;
1530 struct v4l2_ctrl *ctrl = ref->ctrl;
1533 if (ctrl->is_private)
1536 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
1538 ret = handler_new_ref(hdl, ctrl);
1595 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active)
1601 if (ctrl == NULL)
1606 old = test_and_set_bit(4, &ctrl->flags);
1609 old = test_and_clear_bit(4, &ctrl->flags);
1611 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS);
1621 void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
1625 if (ctrl == NULL)
1628 v4l2_ctrl_lock(ctrl);
1631 old = test_and_set_bit(1, &ctrl->flags);
1634 old = test_and_clear_bit(1, &ctrl->flags);
1636 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_FLAGS);
1637 v4l2_ctrl_unlock(ctrl);
1642 static void log_ctrl(const struct v4l2_ctrl *ctrl,
1645 if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY))
1647 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
1650 printk(KERN_INFO "%s%s%s: ", prefix, colon, ctrl->name);
1652 switch (ctrl->type) {
1654 printk(KERN_CONT "%d", ctrl->cur.val);
1657 printk(KERN_CONT "%s", ctrl->cur.val ? "true" : "false");
1660 printk(KERN_CONT "%s", ctrl->qmenu[ctrl->cur.val]);
1663 printk(KERN_CONT "0x%08x", ctrl->cur.val);
1666 printk(KERN_CONT "%lld", ctrl->cur.val64);
1669 printk(KERN_CONT "%s", ctrl->cur.string);
1672 printk(KERN_CONT "unknown type %d", ctrl->type);
1675 if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE |
1678 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
1680 if (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)
1682 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE)
1692 struct v4l2_ctrl *ctrl;
1704 list_for_each_entry(ctrl, &hdl->ctrls, node)
1705 if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED))
1706 log_ctrl(ctrl, prefix, colon);
1714 struct v4l2_ctrl *ctrl;
1720 list_for_each_entry(ctrl, &hdl->ctrls, node)
1721 ctrl->done = false;
1723 list_for_each_entry(ctrl, &hdl->ctrls, node) {
1724 struct v4l2_ctrl *master = ctrl->cluster[0];
1729 if (ctrl->done || ctrl->type == V4L2_CTRL_TYPE_BUTTON ||
1730 (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY))
1754 struct v4l2_ctrl *ctrl;
1780 if (id < ref->ctrl->id)
1788 ctrl = ref->ctrl;
1793 qc->id = ctrl->id;
1794 strlcpy(qc->name, ctrl->name, sizeof(qc->name));
1795 qc->minimum = ctrl->minimum;
1796 qc->maximum = ctrl->maximum;
1797 qc->default_value = ctrl->default_value;
1798 if (ctrl->type == V4L2_CTRL_TYPE_MENU)
1801 qc->step = ctrl->step;
1802 qc->flags = ctrl->flags;
1803 qc->type = ctrl->type;
1819 struct v4l2_ctrl *ctrl;
1822 ctrl = v4l2_ctrl_find(hdl, qm->id);
1823 if (!ctrl)
1828 if (ctrl->qmenu == NULL ||
1829 i < ctrl->minimum || i > ctrl->maximum)
1832 if (ctrl->menu_skip_mask & (1 << i))
1835 if (ctrl->qmenu[i] == NULL || ctrl->qmenu[i][0] == '\0')
1837 strlcpy(qm->name, ctrl->qmenu[i], sizeof(qm->name));
1902 struct v4l2_ctrl *ctrl;
1917 ctrl = ref->ctrl;
1918 if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED)
1921 if (ctrl->cluster[0]->ncontrols > 1)
1923 if (ctrl->cluster[0] != ctrl)
1924 ref = find_ref_lock(hdl, ctrl->cluster[0]->id);
1927 h->ctrl = ctrl;
2008 if (helpers[i].ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
2013 struct v4l2_ctrl *ctrl) = cur_to_user;
2019 master = helpers[i].mref->ctrl;
2040 helpers[idx].ctrl);
2060 static int get_ctrl(struct v4l2_ctrl *ctrl, s32 *val)
2062 struct v4l2_ctrl *master = ctrl->cluster[0];
2066 if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
2071 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) {
2075 *val = ctrl->val;
2077 *val = ctrl->cur.val;
2085 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id);
2087 if (ctrl == NULL || !type_is_int(ctrl))
2089 return get_ctrl(ctrl, &control->value);
2099 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl)
2104 WARN_ON(!type_is_int(ctrl));
2105 get_ctrl(ctrl, &val);
2113 Must be called with ctrl->handler->lock held. */
2126 struct v4l2_ctrl *ctrl = master->cluster[i];
2128 if (ctrl == NULL)
2131 if (!ctrl->is_new) {
2132 cur_to_new(ctrl);
2137 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED))
2166 struct v4l2_ctrl *ctrl = helpers[i].ctrl;
2170 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
2178 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED))
2180 ret = validate_new(ctrl, &cs->controls[i]);
2238 master = helpers[i].mref->ctrl;
2261 if (helpers[tmp_idx].ctrl == master)
2274 ret = user_to_new(cs->controls + idx, helpers[idx].ctrl);
2286 helpers[idx].ctrl);
2324 static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, s32 *val)
2326 struct v4l2_ctrl *master = ctrl->cluster[0];
2330 ret = validate_new_int(ctrl, val);
2334 v4l2_ctrl_lock(ctrl);
2344 if (master->is_auto && master->has_volatiles && ctrl == master &&
2347 ctrl->val = *val;
2348 ctrl->is_new = 1;
2350 *val = ctrl->cur.val;
2351 v4l2_ctrl_unlock(ctrl);
2358 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id);
2360 if (ctrl == NULL || !type_is_int(ctrl))
2363 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
2366 return set_ctrl(fh, ctrl, &control->value);
2376 int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
2379 WARN_ON(!type_is_int(ctrl));
2380 return set_ctrl(NULL, ctrl, &val);
2384 void v4l2_ctrl_add_event(struct v4l2_ctrl *ctrl,
2387 v4l2_ctrl_lock(ctrl);
2388 list_add_tail(&sev->node, &ctrl->ev_subs);
2389 if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS &&
2394 if (!(ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY))
2396 fill_event(&ev, ctrl, changes);
2399 v4l2_ctrl_unlock(ctrl);
2403 void v4l2_ctrl_del_event(struct v4l2_ctrl *ctrl,
2406 v4l2_ctrl_lock(ctrl);
2408 v4l2_ctrl_unlock(ctrl);