From patchwork Mon Sep 24 12:53:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 1497531 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) by patchwork1.kernel.org (Postfix) with ESMTP id 581603FE80 for ; Mon, 24 Sep 2012 12:54:17 +0000 (UTC) Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id q8OCsGVH014750 for ; Mon, 24 Sep 2012 07:54:16 -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 q8OCsGhU023992 for ; Mon, 24 Sep 2012 07:54:16 -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, 24 Sep 2012 07:54:16 -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 q8OCsGDa009326 for ; Mon, 24 Sep 2012 07:54:16 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id C76B380699 for ; Mon, 24 Sep 2012 07:54:12 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflp52.itg.ti.com (dflp52.itg.ti.com [128.247.22.96]) by linux.omap.com (Postfix) with ESMTP id CB47A80626 for ; Mon, 24 Sep 2012 07:54:07 -0500 (CDT) Received: from red.ext.ti.com (red.ext.ti.com [192.94.93.37]) by dflp52.itg.ti.com (8.13.7/8.13.8) with ESMTP id q8OCs7ei011866 for ; Mon, 24 Sep 2012 07:54:07 -0500 (CDT) Received: from psmtp.com (na3sys009amx212.postini.com [74.125.149.52]) by red.ext.ti.com (8.13.7/8.13.7) with SMTP id q8OCs63U025836 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 24 Sep 2012 07:54:06 -0500 Received: from mail-da0-f45.google.com ([209.85.210.45]) (using TLSv1) by na3sys009amx212.postini.com ([74.125.148.10]) with SMTP; Mon, 24 Sep 2012 12:54:07 GMT Received: by dadn15 with SMTP id n15so166367dad.4 for ; Mon, 24 Sep 2012 05:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=8Cr5PNnukU6emhkT4dvg1L91YwHdLWMjTylGYERHVIc=; b=z5ADhBZhlDpZI5/nsnVo1/pj2EfBem2KIzq0s8hKRWH8LjC9qr2X7b0cvFfh+YcwYF hhH0niobjz7SVthSH208KXCfBaJxoUhiUA34UJE0PmcQOPRDhHmTFMfBufCe+0UPhfku T7byydeOVFJzzg5pvPGlMgZd+r1HJdMxt6uN0OllB6g3bQS76NyyewATSp0ToNvGVaxn X5HKPtGrPy5tNgXTVp0iREB5e0Zr2BG6/VR9a11sE+OnjCfNMzaRLheOrSl8Zoq/DbBd t+oVgqeuXuqtC5ESfx8x5pU4zXnqVrSRBHmsGRw/Ijxh3RPScpcP3HqyE0920TQiqV1f v67Q== Received: by 10.68.193.194 with SMTP id hq2mr36882301pbc.93.1348491245729; Mon, 24 Sep 2012 05:54:05 -0700 (PDT) Received: from localhost.localdomain ([122.166.13.141]) by mx.google.com with ESMTPS id sr3sm9617540pbc.44.2012.09.24.05.53.55 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 05:54:04 -0700 (PDT) From: Prabhakar To: LMML Subject: [PATCH v5] media: v4l2-ctrl: add a helper function to add standard control with driver specific menu Date: Mon, 24 Sep 2012 18:23:40 +0530 Message-ID: <1348491221-6068-1-git-send-email-prabhakar.lad@ti.com> X-Mailer: git-send-email 1.7.4.1 X-pstn-neptune: 0/0/0.00/0 X-pstn-levels: (S:99.90000/99.90000 CV:99.9000 FC:93.6803 LC:95.5390 R:95.9108 P:95.9108 M:88.1613 C:98.6951 ) X-pstn-dkim: 1 skipped:not-enabled X-pstn-settings: 2 (0.5000:0.0050) s cv GT3 gt2 gt1 r p m c X-pstn-addresses: from [82/3] CC: DLOS , Rob Landley , LDOC , VGER , Hans de Goede , Kyungmin Park , Hans Verkuil , Sylwester Nawrocki , Sakari Ailus , Mauro Carvalho Chehab , Guennadi Liakhovetski 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: , MIME-Version: 1.0 Sender: Errors-To: davinci-linux-open-source-bounces+patchwork-davinci=patchwork.kernel.org@linux.davincidsp.com From: Lad, Prabhakar Add helper function v4l2_ctrl_new_std_menu_items(), which adds a standard menu control, with driver specific menu. 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 Acked-by: Hans Verkuil Acked-by: Laurent Pinchart --- Changes for v5: 1: Fixed some grammatical issues pointed by Hans. Changes for v4: 1: Rather then adding a function to modify the menu, added a helper function, that creates a new standard control with user specific menu. Changes for v3: 1: Fixed style/grammer issues as pointed by Hans. Thanks Hans for providing the description. 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 | 24 +++++++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls.c | 30 +++++++++++++++++++++++++++ include/media/v4l2-ctrls.h | 23 ++++++++++++++++++++ 3 files changed, 77 insertions(+), 0 deletions(-) diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt index 43da22b..b0cb0b8 100644 --- a/Documentation/video4linux/v4l2-controls.txt +++ b/Documentation/video4linux/v4l2-controls.txt @@ -136,11 +136,25 @@ Or alternatively for integer menu controls, by calling v4l2_ctrl_new_int_menu: const struct v4l2_ctrl_ops *ops, u32 id, s32 max, s32 def, const s64 *qmenu_int); +Standard menu controls with a driver specific menu are added by calling +v4l2_ctrl_new_std_menu_items: + + struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items( + struct v4l2_ctrl_handler *hdl, + const struct v4l2_ctrl_ops *ops, u32 id, s32 max, + s32 skip_mask, s32 def, const char * const *qmenu); + These functions are typically called right after the v4l2_ctrl_handler_init: static const s64 exp_bias_qmenu[] = { -2, -1, 0, 1, 2 }; + static const char * const test_pattern[] = { + "Disabled", + "Vertical Bars", + "Solid Black", + "Solid White", + }; v4l2_ctrl_handler_init(&foo->ctrl_handler, nr_of_controls); v4l2_ctrl_new_std(&foo->ctrl_handler, &foo_ctrl_ops, @@ -156,6 +170,9 @@ These functions are typically called right after the v4l2_ctrl_handler_init: ARRAY_SIZE(exp_bias_qmenu) - 1, ARRAY_SIZE(exp_bias_qmenu) / 2 - 1, exp_bias_qmenu); + v4l2_ctrl_new_std_menu_items(&foo->ctrl_handler, &foo_ctrl_ops, + V4L2_CID_TEST_PATTERN, ARRAY_SIZE(test_pattern) - 1, 0, + 0, test_pattern); ... if (foo->ctrl_handler.error) { int err = foo->ctrl_handler.error; @@ -185,6 +202,13 @@ v4l2_ctrl_new_std_menu in that it doesn't have the mask argument and takes as the last argument an array of signed 64-bit integers that form an exact menu item list. +The v4l2_ctrl_new_std_menu_items function is very similar to +v4l2_ctrl_new_std_menu but takes an extra parameter qmenu, which is the driver +specific menu for an otherwise standard menu control. A good example for this +control is the test pattern control for capture/display/sensors devices that +have the capability to generate test patterns. These test patterns are hardware +specific, so the contents of the menu will vary from device to device. + Note that if something fails, the function will return NULL or an error and set ctrl_handler->error to the error code. If ctrl_handler->error was already set, then it will just return and do nothing. This is also true for diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index 41b7732..96c5e73 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -1643,6 +1643,36 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, } EXPORT_SYMBOL(v4l2_ctrl_new_std_menu); +/* Helper function for standard menu controls with driver defined menu */ +struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, + const struct v4l2_ctrl_ops *ops, u32 id, s32 max, + s32 mask, s32 def, const char * const *qmenu) +{ + enum v4l2_ctrl_type type; + const char *name; + u32 flags; + s32 step; + s32 min; + + /* v4l2_ctrl_new_std_menu_items() should only be called for + * standard controls without a standard menu. + */ + if (v4l2_ctrl_get_menu(id)) { + handler_set_err(hdl, -EINVAL); + return NULL; + } + + v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags); + if (type != V4L2_CTRL_TYPE_MENU || qmenu == NULL) { + handler_set_err(hdl, -EINVAL); + return NULL; + } + return v4l2_ctrl_new(hdl, ops, id, name, type, 0, max, mask, def, + flags, qmenu, NULL, NULL); + +} +EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items); + /* Helper function for standard integer menu controls */ struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, const struct v4l2_ctrl_ops *ops, diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 776605f..8db9dbe 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -351,6 +351,29 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, const struct v4l2_ctrl_ops *ops, u32 id, s32 max, s32 mask, s32 def); +/** v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control + * with driver specific menu. + * @hdl: The control handler. + * @ops: The control ops. + * @id: The control ID. + * @max: The control's maximum value. + * @mask: The control's skip mask for menu controls. This makes it + * easy to skip menu items that are not valid. If bit X is set, + * then menu item X is skipped. Of course, this only works for + * menus with <= 32 menu items. There are no menus that come + * close to that number, so this is OK. Should we ever need more, + * then this will have to be extended to a u64 or a bit array. + * @def: The control's default value. + * @qmenu: The new menu. + * + * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific + * menu of this control. + * + */ +struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, + const struct v4l2_ctrl_ops *ops, u32 id, s32 max, + s32 mask, s32 def, const char * const *qmenu); + /** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. * @hdl: The control handler. * @ops: The control ops.