From patchwork Tue Sep 11 07:39:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prabhakar Lad X-Patchwork-Id: 1435921 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 5B38EDFAF3 for ; Tue, 11 Sep 2012 07:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752076Ab2IKHkb (ORCPT ); Tue, 11 Sep 2012 03:40:31 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:52834 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750930Ab2IKHk3 (ORCPT ); Tue, 11 Sep 2012 03:40:29 -0400 Received: from dbdp20.itg.ti.com ([172.24.170.38]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id q8B7dh83000836; Tue, 11 Sep 2012 02:39:43 -0500 Received: from DBDE71.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8B7dYPA026572; Tue, 11 Sep 2012 13:09:35 +0530 (IST) Received: from dbdp32.itg.ti.com (172.24.170.251) by DBDE71.ent.ti.com (172.24.170.149) with Microsoft SMTP Server id 14.1.323.3; Tue, 11 Sep 2012 13:09:34 +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 q8B7dSkm028711; Tue, 11 Sep 2012 13:09:28 +0530 From: Prabhakar Lad To: LMML CC: dlos , , Manjunath Hadli , , "Lad, Prabhakar" , Hans Verkuil , Sakari Ailus , Sylwester Nawrocki , Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Kyungmin Park , Guennadi Liakhovetski , Rob Landley Subject: [PATCH v2] media: v4l2-ctrl: add a helper function to modify the menu Date: Tue, 11 Sep 2012 13:09:02 +0530 Message-ID: <1347349142-2230-1-git-send-email-prabhakar.lad@ti.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Lad, Prabhakar Add a helper function to modify the menu, max and default value to set. 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: Guennadi Liakhovetski Cc: Rob Landley --- Changes for v2: 1: Fixed review comments from Hans, to have return type as void, add WARN_ON() for fail conditions, allow this fucntion to modify the menu of custom controls. Documentation/video4linux/v4l2-controls.txt | 30 +++++++++++++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls.c | 17 +++++++++++++++ include/media/v4l2-ctrls.h | 11 +++++++++ 3 files changed, 58 insertions(+), 0 deletions(-) diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt index 43da22b..160368a 100644 --- a/Documentation/video4linux/v4l2-controls.txt +++ b/Documentation/video4linux/v4l2-controls.txt @@ -367,6 +367,36 @@ it to 0 means that all menu items are supported. You set this mask either through the v4l2_ctrl_config struct for a custom control, or by calling v4l2_ctrl_new_std_menu(). +Changing the menu: +There are situations when menu items may be device specific, in such cases the +framework provides the helper function to change the menu. + +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, + s32 max, u32 menu_skip_mask, s32 def); + +A good example is the test pattern generation, the capture/display/sensors have +the capability to generate test patterns. This test patterns are hardware +specific, In such case the menu will vary from device to device. + +This helper, function is used to modify the menu, 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, 5, 0x3, 1); + Custom Controls =============== diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index d731422..d89b460 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -2666,3 +2666,20 @@ unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait) return 0; } EXPORT_SYMBOL(v4l2_ctrl_poll); + +/* Helper function for modifying the menu */ +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, + s32 max, u32 menu_skip_mask, s32 def) +{ + if (WARN_ON(ctrl->type != V4L2_CTRL_TYPE_MENU || qmenu == NULL)) + return; + + if (WARN_ON(def < 0 || def > max)) + return; + + ctrl->qmenu = qmenu; + ctrl->maximum = max; + ctrl->menu_skip_mask = menu_skip_mask; + ctrl->cur.val = ctrl->val = ctrl->default_value = def; +} +EXPORT_SYMBOL(v4l2_ctrl_modify_menu); diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 776605f..0c91b4e 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -488,6 +488,17 @@ static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) mutex_unlock(ctrl->handler->lock); } +/** + * v4l2_ctrl_modify_menu() - This function is used to modify the menu. + * @ctrl: The control of which menu should be changed. + * @qmenu: The new menu to which control will point to. + * @max: Maximum value of the control. + * @menu_skip_mask: The control's skip mask for menu controls. + * @def: The default value for control to be set. + */ +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, + 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. *