From patchwork Mon Apr 4 11:51:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 685081 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p34BqKOt023451 for ; Mon, 4 Apr 2011 11:52:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752953Ab1DDLwS (ORCPT ); Mon, 4 Apr 2011 07:52:18 -0400 Received: from sj-iport-2.cisco.com ([171.71.176.71]:10601 "EHLO sj-iport-2.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752484Ab1DDLwS (ORCPT ); Mon, 4 Apr 2011 07:52:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=hans.verkuil@cisco.com; l=3134; q=dns/txt; s=iport; t=1301917937; x=1303127537; h=from:to:subject:date:message-id:in-reply-to:references; bh=OaJpAKCe33MPXa2pB5UMTab1FtVmdqEynZU0o+5jGlA=; b=mNSzxoi09CjstKUC3SSxC74v+hLQuGBAklqrObd8s7gm5CdfdznMAVMK Yq4P5D3J0qEgfKEpMMqrb7qAY+bVBKS3WbLcyYc1joGTbMu8nviFXGukN iozN4XJzALJemaGbIprFIYhQLJ+O5zQQAvNVxiAD4yeEamhEjhoWsRR+k s=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvwHAMuvmU2tJV2Z/2dsb2JhbACYW40Cd6RTmyyFawSNI4Nh X-IronPort-AV: E=Sophos;i="4.63,296,1299456000"; d="scan'208";a="330137253" Received: from rcdn-core-2.cisco.com ([173.37.93.153]) by sj-iport-2.cisco.com with ESMTP; 04 Apr 2011 11:52:17 +0000 Received: from OSLEXCP11.eu.tandberg.int ([173.38.136.5]) by rcdn-core-2.cisco.com (8.14.3/8.14.3) with ESMTP id p34BqDrX001853 for ; Mon, 4 Apr 2011 11:52:16 GMT Received: from ultra.eu.tandberg.int ([10.47.1.15]) by OSLEXCP11.eu.tandberg.int with Microsoft SMTPSVC(6.0.3790.4675); Mon, 4 Apr 2011 13:52:13 +0200 Received: from cobaltpc1.rd.tandberg.com (cobaltpc1.rd.tandberg.com [10.47.3.155]) by ultra.eu.tandberg.int (8.13.1/8.13.1) with ESMTP id p34BqDdH009325 for ; Mon, 4 Apr 2011 13:52:14 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Subject: [RFCv1 PATCH 1/9] v4l2-ctrls: add new bitmask control type. Date: Mon, 4 Apr 2011 13:51:46 +0200 Message-Id: <2fa42294dbc167cae5daf227d072b2284f77b1ab.1301916466.git.hans.verkuil@cisco.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1301917914-27437-1-git-send-email-hans.verkuil@cisco.com> References: <1301917914-27437-1-git-send-email-hans.verkuil@cisco.com> X-OriginalArrivalTime: 04 Apr 2011 11:52:13.0986 (UTC) FILETIME=[BD104820:01CBF2BE] Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 04 Apr 2011 11:52:38 +0000 (UTC) Signed-off-by: Hans Verkuil --- drivers/media/video/v4l2-common.c | 3 +++ drivers/media/video/v4l2-ctrls.c | 17 ++++++++++++++++- include/linux/videodev2.h | 1 + 3 files changed, 20 insertions(+), 1 deletions(-) diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c index 06b9f9f..5c6100f 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, menu_items[ctrl->value][0] == '\0') return -EINVAL; } + if (qctrl->type == V4L2_CTRL_TYPE_BITMASK && + (ctrl->value & ~qctrl->maximum)) + return -ERANGE; return 0; } EXPORT_SYMBOL(v4l2_ctrl_check); diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c index 2412f08..f75a1d4 100644 --- a/drivers/media/video/v4l2-ctrls.c +++ b/drivers/media/video/v4l2-ctrls.c @@ -726,6 +726,10 @@ static int validate_new(struct v4l2_ctrl *ctrl) return -EINVAL; return 0; + case V4L2_CTRL_TYPE_BITMASK: + ctrl->val &= ctrl->maximum; + return 0; + case V4L2_CTRL_TYPE_BUTTON: case V4L2_CTRL_TYPE_CTRL_CLASS: ctrl->val64 = 0; @@ -962,13 +966,17 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, /* Sanity checks */ if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE || - max < min || (type == V4L2_CTRL_TYPE_INTEGER && step == 0) || + (type == V4L2_CTRL_TYPE_BITMASK && max == 0) || (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) || (type == V4L2_CTRL_TYPE_STRING && max == 0)) { handler_set_err(hdl, -ERANGE); return NULL; } + if (type != V4L2_CTRL_TYPE_BITMASK && max < min) { + handler_set_err(hdl, -ERANGE); + return NULL; + } if ((type == V4L2_CTRL_TYPE_INTEGER || type == V4L2_CTRL_TYPE_MENU || type == V4L2_CTRL_TYPE_BOOLEAN) && @@ -976,6 +984,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, handler_set_err(hdl, -ERANGE); return NULL; } + if (type == V4L2_CTRL_TYPE_BITMASK && ((def & ~max) || min || step)) { + handler_set_err(hdl, -ERANGE); + return NULL; + } if (type == V4L2_CTRL_TYPE_BUTTON) flags |= V4L2_CTRL_FLAG_WRITE_ONLY; @@ -1217,6 +1229,9 @@ static void log_ctrl(const struct v4l2_ctrl *ctrl, case V4L2_CTRL_TYPE_MENU: printk(KERN_CONT "%s", ctrl->qmenu[ctrl->cur.val]); break; + case V4L2_CTRL_TYPE_BITMASK: + printk(KERN_CONT "0x%x", ctrl->cur.val); + break; case V4L2_CTRL_TYPE_INTEGER64: printk(KERN_CONT "%lld", ctrl->cur.val64); break; diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index aa6c393..92d2fdd 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -1034,6 +1034,7 @@ enum v4l2_ctrl_type { V4L2_CTRL_TYPE_INTEGER64 = 5, V4L2_CTRL_TYPE_CTRL_CLASS = 6, V4L2_CTRL_TYPE_STRING = 7, + V4L2_CTRL_TYPE_BITMASK = 8, }; /* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */