Commit 0176077a authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] v4l2-ctrls: create type_ops

Since compound controls can have non-standard types we need to be able to do
type-specific checks etc. In order to make that easy type operations are added.
There are four operations:

- equal: check if two values are equal
- init: initialize a value
- log: log the value
- validate: validate a new value

The v4l2_ctrl struct adds p_new and p_cur unions at the end of the struct.
This union provides a standard way of accessing control types through a pointer,
which greatly simplifies internal control processing.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent e6bee368
This diff is collapsed.
...@@ -531,13 +531,12 @@ static void v4l_print_query_ext_ctrl(const void *arg, bool write_only) ...@@ -531,13 +531,12 @@ static void v4l_print_query_ext_ctrl(const void *arg, bool write_only)
pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%lld/%lld, " pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%lld/%lld, "
"step=%lld, default=%lld, flags=0x%08x, elem_size=%u, elems=%u, " "step=%lld, default=%lld, flags=0x%08x, elem_size=%u, elems=%u, "
"nr_of_dims=%u, dims=%u,%u,%u,%u,%u,%u,%u,%u\n", "nr_of_dims=%u, dims=%u,%u,%u,%u\n",
p->id, p->type, (int)sizeof(p->name), p->name, p->id, p->type, (int)sizeof(p->name), p->name,
p->minimum, p->maximum, p->minimum, p->maximum,
p->step, p->default_value, p->flags, p->step, p->default_value, p->flags,
p->elem_size, p->elems, p->nr_of_dims, p->elem_size, p->elems, p->nr_of_dims,
p->dims[0], p->dims[1], p->dims[2], p->dims[3], p->dims[0], p->dims[1], p->dims[2], p->dims[3]);
p->dims[4], p->dims[5], p->dims[6], p->dims[7]);
} }
static void v4l_print_querymenu(const void *arg, bool write_only) static void v4l_print_querymenu(const void *arg, bool write_only)
......
...@@ -36,6 +36,19 @@ struct v4l2_subscribed_event; ...@@ -36,6 +36,19 @@ struct v4l2_subscribed_event;
struct v4l2_fh; struct v4l2_fh;
struct poll_table_struct; struct poll_table_struct;
/** union v4l2_ctrl_ptr - A pointer to a control value.
* @p_s32: Pointer to a 32-bit signed value.
* @p_s64: Pointer to a 64-bit signed value.
* @p_char: Pointer to a string.
* @p: Pointer to a compound value.
*/
union v4l2_ctrl_ptr {
s32 *p_s32;
s64 *p_s64;
char *p_char;
void *p;
};
/** struct v4l2_ctrl_ops - The control operations that the driver has to provide. /** struct v4l2_ctrl_ops - The control operations that the driver has to provide.
* @g_volatile_ctrl: Get a new value for this control. Generally only relevant * @g_volatile_ctrl: Get a new value for this control. Generally only relevant
* for volatile (and usually read-only) controls such as a control * for volatile (and usually read-only) controls such as a control
...@@ -54,6 +67,23 @@ struct v4l2_ctrl_ops { ...@@ -54,6 +67,23 @@ struct v4l2_ctrl_ops {
int (*s_ctrl)(struct v4l2_ctrl *ctrl); int (*s_ctrl)(struct v4l2_ctrl *ctrl);
}; };
/** struct v4l2_ctrl_type_ops - The control type operations that the driver has to provide.
* @equal: return true if both values are equal.
* @init: initialize the value.
* @log: log the value.
* @validate: validate the value. Return 0 on success and a negative value otherwise.
*/
struct v4l2_ctrl_type_ops {
bool (*equal)(const struct v4l2_ctrl *ctrl,
union v4l2_ctrl_ptr ptr1,
union v4l2_ctrl_ptr ptr2);
void (*init)(const struct v4l2_ctrl *ctrl,
union v4l2_ctrl_ptr ptr);
void (*log)(const struct v4l2_ctrl *ctrl);
int (*validate)(const struct v4l2_ctrl *ctrl,
union v4l2_ctrl_ptr ptr);
};
typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv); typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
/** struct v4l2_ctrl - The control structure. /** struct v4l2_ctrl - The control structure.
...@@ -89,6 +119,7 @@ typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv); ...@@ -89,6 +119,7 @@ typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
* value, then the whole cluster is in manual mode. Drivers should * value, then the whole cluster is in manual mode. Drivers should
* never set this flag directly. * never set this flag directly.
* @ops: The control ops. * @ops: The control ops.
* @type_ops: The control type ops.
* @id: The control ID. * @id: The control ID.
* @name: The control name. * @name: The control name.
* @type: The control type. * @type: The control type.
...@@ -137,6 +168,7 @@ struct v4l2_ctrl { ...@@ -137,6 +168,7 @@ struct v4l2_ctrl {
unsigned int manual_mode_value:8; unsigned int manual_mode_value:8;
const struct v4l2_ctrl_ops *ops; const struct v4l2_ctrl_ops *ops;
const struct v4l2_ctrl_type_ops *type_ops;
u32 id; u32 id;
const char *name; const char *name;
enum v4l2_ctrl_type type; enum v4l2_ctrl_type type;
...@@ -164,6 +196,9 @@ struct v4l2_ctrl { ...@@ -164,6 +196,9 @@ struct v4l2_ctrl {
char *string; char *string;
void *p; void *p;
} cur; } cur;
union v4l2_ctrl_ptr p_new;
union v4l2_ctrl_ptr p_cur;
}; };
/** struct v4l2_ctrl_ref - The control reference. /** struct v4l2_ctrl_ref - The control reference.
...@@ -217,6 +252,7 @@ struct v4l2_ctrl_handler { ...@@ -217,6 +252,7 @@ struct v4l2_ctrl_handler {
/** struct v4l2_ctrl_config - Control configuration structure. /** struct v4l2_ctrl_config - Control configuration structure.
* @ops: The control ops. * @ops: The control ops.
* @type_ops: The control type ops. Only needed for compound controls.
* @id: The control ID. * @id: The control ID.
* @name: The control name. * @name: The control name.
* @type: The control type. * @type: The control type.
...@@ -241,6 +277,7 @@ struct v4l2_ctrl_handler { ...@@ -241,6 +277,7 @@ struct v4l2_ctrl_handler {
*/ */
struct v4l2_ctrl_config { struct v4l2_ctrl_config {
const struct v4l2_ctrl_ops *ops; const struct v4l2_ctrl_ops *ops;
const struct v4l2_ctrl_type_ops *type_ops;
u32 id; u32 id;
const char *name; const char *name;
enum v4l2_ctrl_type type; enum v4l2_ctrl_type type;
......
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