media: v4l2_ctrl: Add p_def to v4l2_ctrl_config
Subsystems (2)
PATCH v4 1/6 media: v4l2_ctrl: Add p_def to v4l2_ctrl_config
This allows setting the default value on compound controls created via v4l2_ctrl_new_custom.
--- drivers/media/v4l2-core/v4l2-ctrls.c | 2 +- include/media/v4l2-ctrls.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +1 -1
@@ -2690,7 +2690,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, type, min, max, is_menu ? cfg->menu_skip_mask : step, def, cfg->dims, cfg->elem_size, - flags, qmenu, qmenu_int, ptr_null, priv); + flags, qmenu, qmenu_int, cfg->p_def, priv);if (ctrl) ctrl->is_private = cfg->is_private;return ctrl;
include/media/v4l2-ctrls.h +2 -0
@@ -382,6 +382,7 @@ struct v4l2_ctrl_handler {* @max: The control's maximum value. * @step: The control's step value for non-menu controls. * @def: The control's default value. +* @p_def: The control's default value for compound controls. * @dims: The size of each dimension. * @elem_size: The size in bytes of the control. * @flags: The control's flags.
@@ -410,6 +411,7 @@ struct v4l2_ctrl_config {s64 max;u64 step;s64 def; +union v4l2_ctrl_ptr p_def;u32 dims[V4L2_CTRL_MAX_DIMS ];u32 elem_size;u32 flags;
Signature · 1 line
2.24.0.rc1
PATCH v4 2/6 media: v4l2_ctrl: Add const pointer to ctrl_ptr
This pointer is used to point to data that is constant. Thanks to this we can avoid a lot of casting and we make more clear when the data is constant or variable.
--- include/media/v4l2-ctrls.h | 2 ++ 1 file changed, 2 insertions(+)
include/media/v4l2-ctrls.h +2 -0
@@ -56,6 +56,7 @@ struct poll_table_struct;* @p_hevc_slice_params: Pointer to an HEVC slice parameters structure. * @p_area: Pointer to an area. * @p: Pointer to a compound value. +* @p_const: Pointer to a constant compound value. */ union v4l2_ctrl_ptr {s32 *p_s32;
@@ -78,6 +79,7 @@ union v4l2_ctrl_ptr {struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;struct v4l2_area *p_area;void *p; +const void *p_const; };/**
Signature · 1 line
2.24.0.rc1
PATCH v4 3/6 media: vivid: Add an area control
In reply to Ricardo Ribalda DelgadoThis control represents a generic read/write area.
--- drivers/media/platform/vivid/vivid-ctrls.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/media/platform/vivid/vivid-ctrls.c +14 -0
@@ -32,6 +32,7 @@#define VIVID_CID_U32_ARRAY (VIVID_CID_CUSTOM_BASE + 8)#define VIVID_CID_U16_MATRIX (VIVID_CID_CUSTOM_BASE + 9)#define VIVID_CID_U8_4D_ARRAY (VIVID_CID_CUSTOM_BASE + 10) +#define VIVID_CID_AREA (VIVID_CID_CUSTOM_BASE + 11)#define VIVID_CID_VIVID_BASE (0x00f00000 | 0xf000)#define VIVID_CID_VIVID_CLASS (0x00f00000 | 1)
@@ -266,6 +267,18 @@ static const struct v4l2_ctrl_config vivid_ctrl_disconnect = { .type = V4L2_CTRL_TYPE_BUTTON, }; +static const struct v4l2_area area = { + .width =1000 , + .height =2000 , +}; + +static const struct v4l2_ctrl_config vivid_ctrl_area = { + .ops = &vivid_user_gen_ctrl_ops, + .id =VIVID_CID_AREA , + .name ="Area" , + .type =V4L2_CTRL_TYPE_AREA , + .p_def.p_const = &area, +};/* Framebuffer Controls */
@@ -1574,6 +1587,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap, dev->string =v4l2_ctrl_new_custom (hdl_user_gen, &vivid_ctrl_string,NULL ); dev->bitmask =v4l2_ctrl_new_custom (hdl_user_gen, &vivid_ctrl_bitmask,NULL ); dev->int_menu =v4l2_ctrl_new_custom (hdl_user_gen, &vivid_ctrl_int_menu,NULL ); +v4l2_ctrl_new_custom (hdl_user_gen, &vivid_ctrl_area,NULL );v4l2_ctrl_new_custom (hdl_user_gen, &vivid_ctrl_u32_array,NULL );v4l2_ctrl_new_custom (hdl_user_gen, &vivid_ctrl_u16_matrix,NULL );v4l2_ctrl_new_custom (hdl_user_gen, &vivid_ctrl_u8_4d_array,NULL );
Signature · 1 line
2.24.0.rc1
PATCH v4 4/6 media: v4l2_core: Add p_area to struct v4l2_ext_control
In reply to Ricardo Ribalda DelgadoAllow accessing V4L2_CTRL_TYPE_AREA controls without any casting.
--- include/uapi/linux/videodev2.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/videodev2.h +1 -0
@@ -1684,6 +1684,7 @@ struct v4l2_ext_control {__u8 __user *p_u8;__u16 __user *p_u16;__u32 __user *p_u32; +struct v4l2_area __user *p_area;void __user *ptr; }; } __attribute__ ((packed));
Signature · 1 line
2.24.0.rc1
PATCH v4 5/6 Documentation: v42l_core: v4l2_ext_control
In reply to Ricardo Ribalda DelgadoDescribe p_area field from v4l2_ext_ctrl
--- Documentation/media/uapi/v4l/vidioc-g-ext-ctrls.rst | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/media/uapi/v4l/vidioc-g-ext-ctrls.rst +5 -0
@@ -198,6 +198,11 @@ still cause this situation. - ``p_u32`` - A pointer to a matrix control of unsigned 32-bit values. Valid if this control is of type ``V4L2_CTRL_TYPE_U32``. + * - + - :c:type:`v4l2_area` * + - ``p_area`` + - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is + of type ``V4L2_CTRL_TYPE_AREA``. * - - void * - ``ptr``
Signature · 1 line
2.24.0.rc1
PATCH v4 6/6 media: v4l2-ctrl: Use p_const when possible
In reply to Ricardo Ribalda DelgadoAfter adding a const pointer to ctrl_ptr, lets use it where it make sense.
--- drivers/media/v4l2-core/v4l2-ctrls.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls.c +9 -8
@@ -1556,7 +1556,8 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,if (ctrl->is_int)return ptr1.p_s32[idx] == ptr2.p_s32[idx]; idx *= ctrl->elem_size; -return !memcmp (ptr1.p + idx, ptr2.p + idx, ctrl->elem_size); +return !memcmp (ptr1.p_const + idx, ptr2.p_const + idx, + ctrl->elem_size); } }
@@ -1566,8 +1567,8 @@ static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx,struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;void *p = ptr.p + idx * ctrl->elem_size; -if (ctrl->p_def.p) -memcpy (p, ctrl->p_def.p, ctrl->elem_size); +if (ctrl->p_def.p_const) +memcpy (p, ctrl->p_def.p_const, ctrl->elem_size);else memset (p,0 , ctrl->elem_size);
@@ -1954,7 +1955,7 @@ static int ptr_to_user(struct v4l2_ext_control *c,u32 len;if (ctrl->is_ptr && !ctrl->is_string) -return copy_to_user (c->ptr, ptr.p, c->size) ? +return copy_to_user (c->ptr, ptr.p_const, c->size) ? -EFAULT :0 ;switch (ctrl->type) {
@@ -2069,7 +2070,7 @@ static void ptr_to_ptr(struct v4l2_ctrl *ctrl, {if (ctrl ==NULL )return ; -memcpy (to.p, from.p, ctrl->elems * ctrl->elem_size); +memcpy (to.p, from.p_const, ctrl->elems * ctrl->elem_size); }/* Copy the new value to the current value. */
@@ -2587,7 +2588,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, is_array) sz_extra += 2 * tot_ctrl_size; -if (type >=V4L2_CTRL_COMPOUND_TYPES && p_def.p) +if (type >=V4L2_CTRL_COMPOUND_TYPES && p_def.p_const) sz_extra += elem_size; ctrl =kvzalloc (sizeof (*ctrl) + sz_extra,GFP_KERNEL );
@@ -2634,9 +2635,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, ctrl->p_cur.p = &ctrl->cur.val; } -if (type >=V4L2_CTRL_COMPOUND_TYPES && p_def.p) { +if (type >=V4L2_CTRL_COMPOUND_TYPES && p_def.p_const) { ctrl->p_def.p = ctrl->p_cur.p + tot_ctrl_size; -memcpy (ctrl->p_def.p, p_def.p, elem_size); +memcpy (ctrl->p_def.p, p_def.p_const, elem_size); }for (idx =0 ; idx < elems; idx++) {
Signature · 1 line
2.24.0.rc1