Commit 515f3287 authored by Sylwester Nawrocki's avatar Sylwester Nawrocki Committed by Mauro Carvalho Chehab

[media] V4L: Add helper function for standard integer menu controls

This patch adds v4l2_ctrl_new_int_menu() helper function which can be used
in drivers for creating standard integer menu control with driver-specific
menu item list. It is similar to v4l2_ctrl_new_std_menu(), except it doesn't
have a mask parameter and an additional qmenu parameter allows passing
an array of signed 64-bit integers as the menu item list.
Signed-off-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Acked-by: default avatarSakari Ailus <sakari.ailus@iki.fi>
Tested-by: default avatarSakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 6491d1ad
...@@ -130,8 +130,18 @@ Menu controls are added by calling v4l2_ctrl_new_std_menu: ...@@ -130,8 +130,18 @@ Menu controls are added by calling v4l2_ctrl_new_std_menu:
const struct v4l2_ctrl_ops *ops, const struct v4l2_ctrl_ops *ops,
u32 id, s32 max, s32 skip_mask, s32 def); u32 id, s32 max, s32 skip_mask, s32 def);
Or alternatively for integer menu controls, by calling v4l2_ctrl_new_int_menu:
struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ops,
u32 id, s32 max, s32 def, const s64 *qmenu_int);
These functions are typically called right after the v4l2_ctrl_handler_init: These functions are typically called right after the v4l2_ctrl_handler_init:
static const s64 exp_bias_qmenu[] = {
-2, -1, 0, 1, 2
};
v4l2_ctrl_handler_init(&foo->ctrl_handler, nr_of_controls); v4l2_ctrl_handler_init(&foo->ctrl_handler, nr_of_controls);
v4l2_ctrl_new_std(&foo->ctrl_handler, &foo_ctrl_ops, v4l2_ctrl_new_std(&foo->ctrl_handler, &foo_ctrl_ops,
V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
...@@ -141,6 +151,11 @@ These functions are typically called right after the v4l2_ctrl_handler_init: ...@@ -141,6 +151,11 @@ These functions are typically called right after the v4l2_ctrl_handler_init:
V4L2_CID_POWER_LINE_FREQUENCY, V4L2_CID_POWER_LINE_FREQUENCY,
V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0,
V4L2_CID_POWER_LINE_FREQUENCY_DISABLED); V4L2_CID_POWER_LINE_FREQUENCY_DISABLED);
v4l2_ctrl_new_int_menu(&foo->ctrl_handler, &foo_ctrl_ops,
V4L2_CID_EXPOSURE_BIAS,
ARRAY_SIZE(exp_bias_qmenu) - 1,
ARRAY_SIZE(exp_bias_qmenu) / 2 - 1,
exp_bias_qmenu);
... ...
if (foo->ctrl_handler.error) { if (foo->ctrl_handler.error) {
int err = foo->ctrl_handler.error; int err = foo->ctrl_handler.error;
...@@ -164,6 +179,12 @@ controls. There is no min argument since that is always 0 for menu controls, ...@@ -164,6 +179,12 @@ controls. There is no min argument since that is always 0 for menu controls,
and instead of a step there is a skip_mask argument: if bit X is 1, then menu and instead of a step there is a skip_mask argument: if bit X is 1, then menu
item X is skipped. item X is skipped.
The v4l2_ctrl_new_int_menu function creates a new standard integer menu
control with driver-specific items in the menu. It differs from
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.
Note that if something fails, the function will return NULL or an error and 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 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 set, then it will just return and do nothing. This is also true for
......
...@@ -1544,6 +1544,27 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, ...@@ -1544,6 +1544,27 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
} }
EXPORT_SYMBOL(v4l2_ctrl_new_std_menu); EXPORT_SYMBOL(v4l2_ctrl_new_std_menu);
/* 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,
u32 id, s32 max, s32 def, const s64 *qmenu_int)
{
const char *name;
enum v4l2_ctrl_type type;
s32 min;
s32 step;
u32 flags;
v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
if (type != V4L2_CTRL_TYPE_INTEGER_MENU) {
handler_set_err(hdl, -EINVAL);
return NULL;
}
return v4l2_ctrl_new(hdl, ops, id, name, type,
0, max, 0, def, flags, NULL, qmenu_int, NULL);
}
EXPORT_SYMBOL(v4l2_ctrl_new_int_menu);
/* Add a control from another handler to this handler */ /* Add a control from another handler to this handler */
struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl *ctrl) struct v4l2_ctrl *ctrl)
......
...@@ -351,6 +351,23 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, ...@@ -351,6 +351,23 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ops, const struct v4l2_ctrl_ops *ops,
u32 id, s32 max, s32 mask, s32 def); u32 id, s32 max, s32 mask, s32 def);
/** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
* @hdl: The control handler.
* @ops: The control ops.
* @id: The control ID.
* @max: The control's maximum value.
* @def: The control's default value.
* @qmenu_int: The control's menu entries.
*
* Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly
* takes as an argument an array of integers determining the menu items.
*
* If @id refers to a non-integer-menu control, then this function will return NULL.
*/
struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ops,
u32 id, s32 max, s32 def, const s64 *qmenu_int);
/** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler. /** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler.
* @hdl: The control handler. * @hdl: The control handler.
* @ctrl: The control to add. * @ctrl: The control to add.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment