diff options
| author | Hans Verkuil <hans.verkuil@cisco.com> | 2011-05-23 03:07:05 -0400 |
|---|---|---|
| committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-07-27 16:55:38 -0400 |
| commit | fa4d7096d1fb7c012ebaacefee132007a21e0965 (patch) | |
| tree | b33643476d3df4c675b7edaada6a0f35d3837272 | |
| parent | 1de5be5e91ee10d8f42be2aebc1cede718b48d50 (diff) | |
[media] v4l2-ctrls: add new bitmask control type
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
| -rw-r--r-- | drivers/media/video/v4l2-common.c | 3 | ||||
| -rw-r--r-- | drivers/media/video/v4l2-ctrls.c | 18 | ||||
| -rw-r--r-- | include/linux/videodev2.h | 1 |
3 files changed, 21 insertions, 1 deletions
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c index 06b9f9f82013..5c6100fb4072 100644 --- a/drivers/media/video/v4l2-common.c +++ b/drivers/media/video/v4l2-common.c | |||
| @@ -105,6 +105,9 @@ int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl, | |||
| 105 | menu_items[ctrl->value][0] == '\0') | 105 | menu_items[ctrl->value][0] == '\0') |
| 106 | return -EINVAL; | 106 | return -EINVAL; |
| 107 | } | 107 | } |
| 108 | if (qctrl->type == V4L2_CTRL_TYPE_BITMASK && | ||
| 109 | (ctrl->value & ~qctrl->maximum)) | ||
| 110 | return -ERANGE; | ||
| 108 | return 0; | 111 | return 0; |
| 109 | } | 112 | } |
| 110 | EXPORT_SYMBOL(v4l2_ctrl_check); | 113 | EXPORT_SYMBOL(v4l2_ctrl_check); |
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c index 0e8a28f37af9..86554b5cdca0 100644 --- a/drivers/media/video/v4l2-ctrls.c +++ b/drivers/media/video/v4l2-ctrls.c | |||
| @@ -805,6 +805,10 @@ static int validate_new_int(const struct v4l2_ctrl *ctrl, s32 *pval) | |||
| 805 | return -EINVAL; | 805 | return -EINVAL; |
| 806 | return 0; | 806 | return 0; |
| 807 | 807 | ||
| 808 | case V4L2_CTRL_TYPE_BITMASK: | ||
| 809 | *pval &= ctrl->maximum; | ||
| 810 | return 0; | ||
| 811 | |||
| 808 | case V4L2_CTRL_TYPE_BUTTON: | 812 | case V4L2_CTRL_TYPE_BUTTON: |
| 809 | case V4L2_CTRL_TYPE_CTRL_CLASS: | 813 | case V4L2_CTRL_TYPE_CTRL_CLASS: |
| 810 | *pval = 0; | 814 | *pval = 0; |
| @@ -825,6 +829,7 @@ static int validate_new(const struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c | |||
| 825 | case V4L2_CTRL_TYPE_INTEGER: | 829 | case V4L2_CTRL_TYPE_INTEGER: |
| 826 | case V4L2_CTRL_TYPE_BOOLEAN: | 830 | case V4L2_CTRL_TYPE_BOOLEAN: |
| 827 | case V4L2_CTRL_TYPE_MENU: | 831 | case V4L2_CTRL_TYPE_MENU: |
| 832 | case V4L2_CTRL_TYPE_BITMASK: | ||
| 828 | case V4L2_CTRL_TYPE_BUTTON: | 833 | case V4L2_CTRL_TYPE_BUTTON: |
| 829 | case V4L2_CTRL_TYPE_CTRL_CLASS: | 834 | case V4L2_CTRL_TYPE_CTRL_CLASS: |
| 830 | return validate_new_int(ctrl, &c->value); | 835 | return validate_new_int(ctrl, &c->value); |
| @@ -1063,13 +1068,17 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, | |||
| 1063 | 1068 | ||
| 1064 | /* Sanity checks */ | 1069 | /* Sanity checks */ |
| 1065 | if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE || | 1070 | if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE || |
| 1066 | max < min || | ||
| 1067 | (type == V4L2_CTRL_TYPE_INTEGER && step == 0) || | 1071 | (type == V4L2_CTRL_TYPE_INTEGER && step == 0) || |
| 1072 | (type == V4L2_CTRL_TYPE_BITMASK && max == 0) || | ||
| 1068 | (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) || | 1073 | (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) || |
| 1069 | (type == V4L2_CTRL_TYPE_STRING && max == 0)) { | 1074 | (type == V4L2_CTRL_TYPE_STRING && max == 0)) { |
| 1070 | handler_set_err(hdl, -ERANGE); | 1075 | handler_set_err(hdl, -ERANGE); |
| 1071 | return NULL; | 1076 | return NULL; |
| 1072 | } | 1077 | } |
| 1078 | if (type != V4L2_CTRL_TYPE_BITMASK && max < min) { | ||
| 1079 | handler_set_err(hdl, -ERANGE); | ||
| 1080 | return NULL; | ||
| 1081 | } | ||
| 1073 | if ((type == V4L2_CTRL_TYPE_INTEGER || | 1082 | if ((type == V4L2_CTRL_TYPE_INTEGER || |
| 1074 | type == V4L2_CTRL_TYPE_MENU || | 1083 | type == V4L2_CTRL_TYPE_MENU || |
| 1075 | type == V4L2_CTRL_TYPE_BOOLEAN) && | 1084 | type == V4L2_CTRL_TYPE_BOOLEAN) && |
| @@ -1077,6 +1086,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, | |||
| 1077 | handler_set_err(hdl, -ERANGE); | 1086 | handler_set_err(hdl, -ERANGE); |
| 1078 | return NULL; | 1087 | return NULL; |
| 1079 | } | 1088 | } |
| 1089 | if (type == V4L2_CTRL_TYPE_BITMASK && ((def & ~max) || min || step)) { | ||
| 1090 | handler_set_err(hdl, -ERANGE); | ||
| 1091 | return NULL; | ||
| 1092 | } | ||
| 1080 | 1093 | ||
| 1081 | if (type == V4L2_CTRL_TYPE_BUTTON) | 1094 | if (type == V4L2_CTRL_TYPE_BUTTON) |
| 1082 | flags |= V4L2_CTRL_FLAG_WRITE_ONLY; | 1095 | flags |= V4L2_CTRL_FLAG_WRITE_ONLY; |
| @@ -1357,6 +1370,9 @@ static void log_ctrl(const struct v4l2_ctrl *ctrl, | |||
| 1357 | case V4L2_CTRL_TYPE_MENU: | 1370 | case V4L2_CTRL_TYPE_MENU: |
| 1358 | printk(KERN_CONT "%s", ctrl->qmenu[ctrl->cur.val]); | 1371 | printk(KERN_CONT "%s", ctrl->qmenu[ctrl->cur.val]); |
| 1359 | break; | 1372 | break; |
| 1373 | case V4L2_CTRL_TYPE_BITMASK: | ||
| 1374 | printk(KERN_CONT "0x%08x", ctrl->cur.val); | ||
| 1375 | break; | ||
| 1360 | case V4L2_CTRL_TYPE_INTEGER64: | 1376 | case V4L2_CTRL_TYPE_INTEGER64: |
| 1361 | printk(KERN_CONT "%lld", ctrl->cur.val64); | 1377 | printk(KERN_CONT "%lld", ctrl->cur.val64); |
| 1362 | break; | 1378 | break; |
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index f002006fc0a9..148d1a51ca22 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h | |||
| @@ -1040,6 +1040,7 @@ enum v4l2_ctrl_type { | |||
| 1040 | V4L2_CTRL_TYPE_INTEGER64 = 5, | 1040 | V4L2_CTRL_TYPE_INTEGER64 = 5, |
| 1041 | V4L2_CTRL_TYPE_CTRL_CLASS = 6, | 1041 | V4L2_CTRL_TYPE_CTRL_CLASS = 6, |
| 1042 | V4L2_CTRL_TYPE_STRING = 7, | 1042 | V4L2_CTRL_TYPE_STRING = 7, |
| 1043 | V4L2_CTRL_TYPE_BITMASK = 8, | ||
| 1043 | }; | 1044 | }; |
| 1044 | 1045 | ||
| 1045 | /* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */ | 1046 | /* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */ |
