aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLad, Prabhakar <prabhakar.lad@ti.com>2012-09-18 14:54:38 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-10-05 20:48:03 -0400
commit117a711a2c37a0309a3e39fbd13486642b63453b (patch)
tree27fc0524ae0d20d5280a42d391ec36cc93036acb
parent5ebef0fbe0f72fa911088800c5d0bc7a872c35de (diff)
[media] media: v4l2-ctrl: add a helper function to add standard control with driver specific menu
Add helper function v4l2_ctrl_new_std_menu_items(), which adds a standard menu control, with driver specific menu. Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com> Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--Documentation/video4linux/v4l2-controls.txt24
-rw-r--r--drivers/media/v4l2-core/v4l2-ctrls.c30
-rw-r--r--include/media/v4l2-ctrls.h23
3 files changed, 77 insertions, 0 deletions
diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt
index 54270df99d5c..cfe52c798d74 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:
136 const struct v4l2_ctrl_ops *ops, 136 const struct v4l2_ctrl_ops *ops,
137 u32 id, s32 max, s32 def, const s64 *qmenu_int); 137 u32 id, s32 max, s32 def, const s64 *qmenu_int);
138 138
139Standard menu controls with a driver specific menu are added by calling
140v4l2_ctrl_new_std_menu_items:
141
142 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(
143 struct v4l2_ctrl_handler *hdl,
144 const struct v4l2_ctrl_ops *ops, u32 id, s32 max,
145 s32 skip_mask, s32 def, const char * const *qmenu);
146
139These functions are typically called right after the v4l2_ctrl_handler_init: 147These functions are typically called right after the v4l2_ctrl_handler_init:
140 148
141 static const s64 exp_bias_qmenu[] = { 149 static const s64 exp_bias_qmenu[] = {
142 -2, -1, 0, 1, 2 150 -2, -1, 0, 1, 2
143 }; 151 };
152 static const char * const test_pattern[] = {
153 "Disabled",
154 "Vertical Bars",
155 "Solid Black",
156 "Solid White",
157 };
144 158
145 v4l2_ctrl_handler_init(&foo->ctrl_handler, nr_of_controls); 159 v4l2_ctrl_handler_init(&foo->ctrl_handler, nr_of_controls);
146 v4l2_ctrl_new_std(&foo->ctrl_handler, &foo_ctrl_ops, 160 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:
156 ARRAY_SIZE(exp_bias_qmenu) - 1, 170 ARRAY_SIZE(exp_bias_qmenu) - 1,
157 ARRAY_SIZE(exp_bias_qmenu) / 2 - 1, 171 ARRAY_SIZE(exp_bias_qmenu) / 2 - 1,
158 exp_bias_qmenu); 172 exp_bias_qmenu);
173 v4l2_ctrl_new_std_menu_items(&foo->ctrl_handler, &foo_ctrl_ops,
174 V4L2_CID_TEST_PATTERN, ARRAY_SIZE(test_pattern) - 1, 0,
175 0, test_pattern);
159 ... 176 ...
160 if (foo->ctrl_handler.error) { 177 if (foo->ctrl_handler.error) {
161 int err = foo->ctrl_handler.error; 178 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
185as the last argument an array of signed 64-bit integers that form an exact 202as the last argument an array of signed 64-bit integers that form an exact
186menu item list. 203menu item list.
187 204
205The v4l2_ctrl_new_std_menu_items function is very similar to
206v4l2_ctrl_new_std_menu but takes an extra parameter qmenu, which is the driver
207specific menu for an otherwise standard menu control. A good example for this
208control is the test pattern control for capture/display/sensors devices that
209have the capability to generate test patterns. These test patterns are hardware
210specific, so the contents of the menu will vary from device to device.
211
188Note that if something fails, the function will return NULL or an error and 212Note that if something fails, the function will return NULL or an error and
189set ctrl_handler->error to the error code. If ctrl_handler->error was already 213set ctrl_handler->error to the error code. If ctrl_handler->error was already
190set, then it will just return and do nothing. This is also true for 214set, 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 0bcef2b52cb1..207bcd8dee11 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -1650,6 +1650,36 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
1650} 1650}
1651EXPORT_SYMBOL(v4l2_ctrl_new_std_menu); 1651EXPORT_SYMBOL(v4l2_ctrl_new_std_menu);
1652 1652
1653/* Helper function for standard menu controls with driver defined menu */
1654struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
1655 const struct v4l2_ctrl_ops *ops, u32 id, s32 max,
1656 s32 mask, s32 def, const char * const *qmenu)
1657{
1658 enum v4l2_ctrl_type type;
1659 const char *name;
1660 u32 flags;
1661 s32 step;
1662 s32 min;
1663
1664 /* v4l2_ctrl_new_std_menu_items() should only be called for
1665 * standard controls without a standard menu.
1666 */
1667 if (v4l2_ctrl_get_menu(id)) {
1668 handler_set_err(hdl, -EINVAL);
1669 return NULL;
1670 }
1671
1672 v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
1673 if (type != V4L2_CTRL_TYPE_MENU || qmenu == NULL) {
1674 handler_set_err(hdl, -EINVAL);
1675 return NULL;
1676 }
1677 return v4l2_ctrl_new(hdl, ops, id, name, type, 0, max, mask, def,
1678 flags, qmenu, NULL, NULL);
1679
1680}
1681EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items);
1682
1653/* Helper function for standard integer menu controls */ 1683/* Helper function for standard integer menu controls */
1654struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, 1684struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
1655 const struct v4l2_ctrl_ops *ops, 1685 const struct v4l2_ctrl_ops *ops,
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 801adb466bd2..96509119f28f 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,
351 const struct v4l2_ctrl_ops *ops, 351 const struct v4l2_ctrl_ops *ops,
352 u32 id, s32 max, s32 mask, s32 def); 352 u32 id, s32 max, s32 mask, s32 def);
353 353
354/** v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
355 * with driver specific menu.
356 * @hdl: The control handler.
357 * @ops: The control ops.
358 * @id: The control ID.
359 * @max: The control's maximum value.
360 * @mask: The control's skip mask for menu controls. This makes it
361 * easy to skip menu items that are not valid. If bit X is set,
362 * then menu item X is skipped. Of course, this only works for
363 * menus with <= 32 menu items. There are no menus that come
364 * close to that number, so this is OK. Should we ever need more,
365 * then this will have to be extended to a u64 or a bit array.
366 * @def: The control's default value.
367 * @qmenu: The new menu.
368 *
369 * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
370 * menu of this control.
371 *
372 */
373struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
374 const struct v4l2_ctrl_ops *ops, u32 id, s32 max,
375 s32 mask, s32 def, const char * const *qmenu);
376
354/** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. 377/** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
355 * @hdl: The control handler. 378 * @hdl: The control handler.
356 * @ops: The control ops. 379 * @ops: The control ops.