From patchwork Mon Sep 10 11:57:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prabhakar Lad X-Patchwork-Id: 1431831 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from devils.ext.ti.com (devils.ext.ti.com [198.47.26.153]) by patchwork2.kernel.org (Postfix) with ESMTP id 91A72DF28C for ; Mon, 10 Sep 2012 11:59:54 +0000 (UTC) Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id q8ABvt1a013817; Mon, 10 Sep 2012 06:57:55 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8ABvs9f005392; Mon, 10 Sep 2012 06:57:54 -0500 Received: from dlelxv24.itg.ti.com (172.17.1.199) by dfle72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.1.323.3; Mon, 10 Sep 2012 06:57:54 -0500 Received: from linux.omap.com (dlelxs01.itg.ti.com [157.170.227.31]) by dlelxv24.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8ABvsn5010812; Mon, 10 Sep 2012 06:57:54 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 9C2AB80627; Mon, 10 Sep 2012 06:57:54 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dbdp20.itg.ti.com (dbdp20.itg.ti.com [172.24.170.38]) by linux.omap.com (Postfix) with ESMTP id 403AF80626 for ; Mon, 10 Sep 2012 06:57:53 -0500 (CDT) Received: from DBDE70.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8ABvlBN022923; Mon, 10 Sep 2012 17:27:48 +0530 (IST) Received: from dbdp32.itg.ti.com (172.24.170.251) by dbde70.ent.ti.com (172.24.170.148) with Microsoft SMTP Server id 14.1.323.3; Mon, 10 Sep 2012 17:27:46 +0530 Received: from localhost.localdomain (dbdp20.itg.ti.com [172.24.170.38]) by dbdp32.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8ABvea4030129; Mon, 10 Sep 2012 17:27:40 +0530 From: Prabhakar Lad To: LMML Subject: [PATCH] media: v4l2-ctrl: add a helper fucntion to modify the menu Date: Mon, 10 Sep 2012 17:27:36 +0530 Message-ID: <1347278256-4560-1-git-send-email-prabhakar.lad@ti.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 CC: dlos , Rob Landley , , , Hans de Goede , Kyungmin Park , Hans Verkuil , Sylwester Nawrocki , Sakari Ailus , Mauro Carvalho Chehab X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com From: Lad, Prabhakar Signed-off-by: Lad, Prabhakar Signed-off-by: Manjunath Hadli Cc: Hans Verkuil Cc: Sakari Ailus Cc: Sylwester Nawrocki Cc: Laurent Pinchart Cc: Mauro Carvalho Chehab Cc: Hans de Goede Cc: Kyungmin Park Cc: Rob Landley --- Documentation/video4linux/v4l2-controls.txt | 26 +++++++++++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls.c | 28 +++++++++++++++++++++++++++ include/media/v4l2-ctrls.h | 14 +++++++++++++ 3 files changed, 68 insertions(+), 0 deletions(-) diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt index 43da22b..54a9539 100644 --- a/Documentation/video4linux/v4l2-controls.txt +++ b/Documentation/video4linux/v4l2-controls.txt @@ -196,6 +196,32 @@ the error code at the end. Saves a lot of repetitive error checking. It is recommended to add controls in ascending control ID order: it will be a bit faster that way. +2.1) Changing the menu of a standard control: +There are suitations when the control is standard but the menu items may be +device specific, in such cases the framework provides the helper to do that. + +struct v4l2_ctrl * v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, + const char * const *qmenu, s32 min, s32 max, + u32 menu_skip_mask, s32 def); + +This helper, function is used to modify the menu, min, max, mask and +the default value to set. +Example for usage: + static const char * const test_pattern[] = { + "Disabled", + "Vertical Bars", + "Vertical Bars", + "Solid Black", + "Solid White", + NULL + }; + struct v4l2_ctrl *test_pattern_ctrl = + v4l2_ctrl_new_std_menu(&foo->ctrl_handler, &foo_ctrl_ops, + V4L2_CID_TEST_PATTERN, V4L2_TEST_PATTERN_DISABLED, 0, + V4L2_TEST_PATTERN_DISABLED); + + v4l2_ctrl_modify_menu(test_pattern_ctrl, test_pattern, 0, 5, 0x3, 0); + 3) Optionally force initial control setup: v4l2_ctrl_handler_setup(&foo->ctrl_handler); diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index d731422..ac0fb28 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -2666,3 +2666,31 @@ unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait) return 0; } EXPORT_SYMBOL(v4l2_ctrl_poll); + +/* Helper function for standard menu controls to modify the menu */ +struct v4l2_ctrl *v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, + const char * const *qmenu, s32 min, + s32 max, u32 menu_skip_mask, s32 def) +{ + if (ctrl->type != V4L2_CTRL_TYPE_MENU) + return NULL; + + if (qmenu == NULL) + return NULL; + + /* Determine if it is standard menu control */ + if (!v4l2_ctrl_get_menu(ctrl->id)) + return NULL; + + if ((def > max) || (max < min)) + return NULL; + + ctrl->qmenu = qmenu; + ctrl->minimum = min; + ctrl->maximum = max; + ctrl->menu_skip_mask = menu_skip_mask; + ctrl->cur.val = ctrl->val = ctrl->default_value = def; + + return ctrl; +} +EXPORT_SYMBOL(v4l2_ctrl_modify_menu); diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 776605f..5b0ea04 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -488,6 +488,20 @@ static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) mutex_unlock(ctrl->handler->lock); } +/** + * v4l2_ctrl_modify_menu() - Modify the menu. This function is used when the + * control is standard but the menu is specific to device. + * @ctrl: The control to change the menu. + * @qmenu: The menu to which control will point to. + * @min: Minimum value of the control. + * @max: Maximum valur of the control. + * @menu_skip_mask: The control's skip mask for menu controls. + * @def: The default value for control. + */ +struct v4l2_ctrl *v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, + const char * const *qmenu, s32 min, + s32 max, u32 menu_skip_mask, s32 def); + /** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver. * @ctrl: The control. *