bcm27xx: update patches from RPi foundation
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0490-media-add-V4L2_CTRL_TYPE_AREA-control-type.patch
1 From 4af6218f1d01e5ae54dc43e4bd2421617c777570 Mon Sep 17 00:00:00 2001
2 From: Ricardo Ribalda Delgado <ribalda@kernel.org>
3 Date: Mon, 7 Oct 2019 12:06:31 -0300
4 Subject: [PATCH] media: add V4L2_CTRL_TYPE_AREA control type
5
6 Commit d1dc49370f8371b00e682ac409aa1987ce641e93 upstream.
7
8 This type contains the width and the height of a rectangular area.
9
10 Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
11 Signed-off-by: Ricardo Ribalda Delgado <ribalda@kernel.org>
12 Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
13 Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
14 ---
15 drivers/media/v4l2-core/v4l2-ctrls.c | 21 ++++++++++++++
16 include/media/v4l2-ctrls.h | 42 ++++++++++++++++++++++++++++
17 include/uapi/linux/videodev2.h | 6 ++++
18 3 files changed, 69 insertions(+)
19
20 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
21 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
22 @@ -1673,6 +1673,7 @@ static int std_validate_compound(const s
23 {
24 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
25 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
26 + struct v4l2_area *area;
27 void *p = ptr.p + idx * ctrl->elem_size;
28
29 switch ((u32)ctrl->type) {
30 @@ -1749,6 +1750,11 @@ static int std_validate_compound(const s
31 zero_padding(p_vp8_frame_header->entropy_header);
32 zero_padding(p_vp8_frame_header->coder_state);
33 break;
34 + case V4L2_CTRL_TYPE_AREA:
35 + area = p;
36 + if (!area->width || !area->height)
37 + return -EINVAL;
38 + break;
39 default:
40 return -EINVAL;
41 }
42 @@ -2422,6 +2428,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(s
43 case V4L2_CTRL_TYPE_VP8_FRAME_HEADER:
44 elem_size = sizeof(struct v4l2_ctrl_vp8_frame_header);
45 break;
46 + case V4L2_CTRL_TYPE_AREA:
47 + elem_size = sizeof(struct v4l2_area);
48 + break;
49 default:
50 if (type < V4L2_CTRL_COMPOUND_TYPES)
51 elem_size = sizeof(s32);
52 @@ -4086,6 +4095,18 @@ int __v4l2_ctrl_s_ctrl_string(struct v4l
53 }
54 EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_string);
55
56 +int __v4l2_ctrl_s_ctrl_area(struct v4l2_ctrl *ctrl,
57 + const struct v4l2_area *area)
58 +{
59 + lockdep_assert_held(ctrl->handler->lock);
60 +
61 + /* It's a driver bug if this happens. */
62 + WARN_ON(ctrl->type != V4L2_CTRL_TYPE_AREA);
63 + *ctrl->p_new.p_area = *area;
64 + return set_ctrl(NULL, ctrl, 0);
65 +}
66 +EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_area);
67 +
68 void v4l2_ctrl_request_complete(struct media_request *req,
69 struct v4l2_ctrl_handler *main_hdl)
70 {
71 --- a/include/media/v4l2-ctrls.h
72 +++ b/include/media/v4l2-ctrls.h
73 @@ -50,6 +50,7 @@ struct poll_table_struct;
74 * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params.
75 * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params.
76 * @p_vp8_frame_header: Pointer to a VP8 frame header structure.
77 + * @p_area: Pointer to an area.
78 * @p: Pointer to a compound value.
79 */
80 union v4l2_ctrl_ptr {
81 @@ -68,6 +69,7 @@ union v4l2_ctrl_ptr {
82 struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
83 struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;
84 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
85 + struct v4l2_area *p_area;
86 void *p;
87 };
88
89 @@ -1063,6 +1065,46 @@ static inline int v4l2_ctrl_s_ctrl_strin
90 v4l2_ctrl_unlock(ctrl);
91
92 return rval;
93 +}
94 +
95 +/**
96 + * __v4l2_ctrl_s_ctrl_area() - Unlocked variant of v4l2_ctrl_s_ctrl_area().
97 + *
98 + * @ctrl: The control.
99 + * @area: The new area.
100 + *
101 + * This sets the control's new area safely by going through the control
102 + * framework. This function assumes the control's handler is already locked,
103 + * allowing it to be used from within the &v4l2_ctrl_ops functions.
104 + *
105 + * This function is for area type controls only.
106 + */
107 +int __v4l2_ctrl_s_ctrl_area(struct v4l2_ctrl *ctrl,
108 + const struct v4l2_area *area);
109 +
110 +/**
111 + * v4l2_ctrl_s_ctrl_area() - Helper function to set a control's area value
112 + * from within a driver.
113 + *
114 + * @ctrl: The control.
115 + * @area: The new area.
116 + *
117 + * This sets the control's new area safely by going through the control
118 + * framework. This function will lock the control's handler, so it cannot be
119 + * used from within the &v4l2_ctrl_ops functions.
120 + *
121 + * This function is for area type controls only.
122 + */
123 +static inline int v4l2_ctrl_s_ctrl_area(struct v4l2_ctrl *ctrl,
124 + const struct v4l2_area *area)
125 +{
126 + int rval;
127 +
128 + v4l2_ctrl_lock(ctrl);
129 + rval = __v4l2_ctrl_s_ctrl_area(ctrl, area);
130 + v4l2_ctrl_unlock(ctrl);
131 +
132 + return rval;
133 }
134
135 /* Internal helper functions that deal with control events. */
136 --- a/include/uapi/linux/videodev2.h
137 +++ b/include/uapi/linux/videodev2.h
138 @@ -427,6 +427,11 @@ struct v4l2_fract {
139 __u32 denominator;
140 };
141
142 +struct v4l2_area {
143 + __u32 width;
144 + __u32 height;
145 +};
146 +
147 /**
148 * struct v4l2_capability - Describes V4L2 device caps returned by VIDIOC_QUERYCAP
149 *
150 @@ -1725,6 +1730,7 @@ enum v4l2_ctrl_type {
151 V4L2_CTRL_TYPE_U8 = 0x0100,
152 V4L2_CTRL_TYPE_U16 = 0x0101,
153 V4L2_CTRL_TYPE_U32 = 0x0102,
154 + V4L2_CTRL_TYPE_AREA = 0x0106,
155 };
156
157 /* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */