kernel: bump 5.4 to 5.4.48
[oweals/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0696-staging-vc04_services-ISP-Add-enum_framesizes-ioctl.patch
1 From 01a1601512893ce9a3353e1686a95a9861f3d685 Mon Sep 17 00:00:00 2001
2 From: Naushir Patuck <naush@raspberrypi.com>
3 Date: Fri, 1 May 2020 14:15:24 +0100
4 Subject: [PATCH] staging: vc04_services: ISP: Add enum_framesizes
5  ioctl
6
7 This is used to enumerate available frame sizes on all nodes
8 apart from statistics output.
9
10 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
11 ---
12  .../bcm2835-isp/bcm2835-v4l2-isp.c            | 48 +++++++++++++++++--
13  .../bcm2835-isp/bcm2835_isp_fmts.h            | 29 +++++++++++
14  2 files changed, 72 insertions(+), 5 deletions(-)
15
16 --- a/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
17 +++ b/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
18 @@ -227,8 +227,9 @@ static const struct bcm2835_isp_fmt *get
19         return NULL;
20  }
21  
22 -static struct bcm2835_isp_fmt *find_format(struct v4l2_format *f,
23 -                                          struct bcm2835_isp_node *node)
24 +static const
25 +struct bcm2835_isp_fmt *find_format_by_fourcc(unsigned int fourcc,
26 +                                             struct bcm2835_isp_node *node)
27  {
28         struct bcm2835_isp_fmt_list *fmts = &node->supported_fmts;
29         struct bcm2835_isp_fmt *fmt;
30 @@ -236,15 +237,22 @@ static struct bcm2835_isp_fmt *find_form
31  
32         for (i = 0; i < fmts->num_entries; i++) {
33                 fmt = &fmts->list[i];
34 -               if (fmt->fourcc == (node_is_stats(node) ?
35 -                                           f->fmt.meta.dataformat :
36 -                                           f->fmt.pix.pixelformat))
37 +               if (fmt->fourcc == fourcc)
38                         return fmt;
39         }
40  
41         return NULL;
42  }
43  
44 +static struct bcm2835_isp_fmt *find_format(struct v4l2_format *f,
45 +                                          struct bcm2835_isp_node *node)
46 +{
47 +       return find_format_by_fourcc(node_is_stats(node) ?
48 +                                    f->fmt.meta.dataformat :
49 +                                    f->fmt.pix.pixelformat,
50 +                                    node);
51 +}
52 +
53  /* vb2_to_mmal_buffer() - converts vb2 buffer header to MMAL
54   *
55   * Copies all the required fields from a VB2 buffer to the MMAL buffer header,
56 @@ -892,6 +900,35 @@ static int bcm2835_isp_node_enum_fmt(str
57         return -EINVAL;
58  }
59  
60 +static int bcm2835_isp_enum_framesizes(struct file *file, void *priv,
61 +                                      struct v4l2_frmsizeenum *fsize)
62 +{
63 +       struct bcm2835_isp_node *node = video_drvdata(file);
64 +       struct bcm2835_isp_dev *dev = node_get_dev(node);
65 +       struct bcm2835_isp_fmt *fmt;
66 +
67 +       if (node_is_stats(node) || fsize->index)
68 +               return -EINVAL;
69 +
70 +       fmt = find_format_by_fourcc(fsize->pixel_format, node);
71 +       if (!fmt) {
72 +               v4l2_err(&dev->v4l2_dev, "Invalid pixel code: %x\n",
73 +                        fsize->pixel_format);
74 +               return -EINVAL;
75 +       }
76 +
77 +       fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
78 +       fsize->stepwise.min_width = MIN_DIM;
79 +       fsize->stepwise.max_width = MAX_DIM;
80 +       fsize->stepwise.step_width = fmt->step_size;
81 +
82 +       fsize->stepwise.min_height = MIN_DIM;
83 +       fsize->stepwise.max_height = MAX_DIM;
84 +       fsize->stepwise.step_height = fmt->step_size;
85 +
86 +       return 0;
87 +}
88 +
89  static int bcm2835_isp_node_try_fmt(struct file *file, void *priv,
90                                     struct v4l2_format *f)
91  {
92 @@ -1046,6 +1083,7 @@ static const struct v4l2_ioctl_ops bcm28
93         .vidioc_enum_fmt_vid_cap        = bcm2835_isp_node_enum_fmt,
94         .vidioc_enum_fmt_vid_out        = bcm2835_isp_node_enum_fmt,
95         .vidioc_enum_fmt_meta_cap       = bcm2835_isp_node_enum_fmt,
96 +       .vidioc_enum_framesizes         = bcm2835_isp_enum_framesizes,
97  
98         .vidioc_reqbufs                 = vb2_ioctl_reqbufs,
99         .vidioc_querybuf                = vb2_ioctl_querybuf,
100 --- a/drivers/staging/vc04_services/bcm2835-isp/bcm2835_isp_fmts.h
101 +++ b/drivers/staging/vc04_services/bcm2835-isp/bcm2835_isp_fmts.h
102 @@ -22,6 +22,7 @@ struct bcm2835_isp_fmt {
103         u32 mmal_fmt;
104         int size_multiplier_x2;
105         enum v4l2_colorspace colorspace;
106 +       unsigned int step_size;
107  };
108  
109  struct bcm2835_isp_fmt_list {
110 @@ -39,6 +40,7 @@ static const struct bcm2835_isp_fmt supp
111                 .mmal_fmt           = MMAL_ENCODING_I420,
112                 .size_multiplier_x2 = 3,
113                 .colorspace         = V4L2_COLORSPACE_SMPTE170M,
114 +               .step_size          = 2,
115         }, {
116                 .fourcc             = V4L2_PIX_FMT_YVU420,
117                 .depth              = 8,
118 @@ -47,6 +49,7 @@ static const struct bcm2835_isp_fmt supp
119                 .mmal_fmt           = MMAL_ENCODING_YV12,
120                 .size_multiplier_x2 = 3,
121                 .colorspace         = V4L2_COLORSPACE_SMPTE170M,
122 +               .step_size          = 2,
123         }, {
124                 .fourcc             = V4L2_PIX_FMT_NV12,
125                 .depth              = 8,
126 @@ -55,6 +58,7 @@ static const struct bcm2835_isp_fmt supp
127                 .mmal_fmt           = MMAL_ENCODING_NV12,
128                 .size_multiplier_x2 = 3,
129                 .colorspace         = V4L2_COLORSPACE_SMPTE170M,
130 +               .step_size          = 2,
131         }, {
132                 .fourcc             = V4L2_PIX_FMT_NV21,
133                 .depth              = 8,
134 @@ -63,6 +67,7 @@ static const struct bcm2835_isp_fmt supp
135                 .mmal_fmt           = MMAL_ENCODING_NV21,
136                 .size_multiplier_x2 = 3,
137                 .colorspace         = V4L2_COLORSPACE_SMPTE170M,
138 +               .step_size          = 2,
139         }, {
140                 .fourcc             = V4L2_PIX_FMT_YUYV,
141                 .depth              = 16,
142 @@ -71,6 +76,7 @@ static const struct bcm2835_isp_fmt supp
143                 .mmal_fmt           = MMAL_ENCODING_YUYV,
144                 .size_multiplier_x2 = 2,
145                 .colorspace         = V4L2_COLORSPACE_SMPTE170M,
146 +               .step_size          = 2,
147         }, {
148                 .fourcc             = V4L2_PIX_FMT_UYVY,
149                 .depth              = 16,
150 @@ -79,6 +85,7 @@ static const struct bcm2835_isp_fmt supp
151                 .mmal_fmt           = MMAL_ENCODING_UYVY,
152                 .size_multiplier_x2 = 2,
153                 .colorspace         = V4L2_COLORSPACE_SMPTE170M,
154 +               .step_size          = 2,
155         }, {
156                 .fourcc             = V4L2_PIX_FMT_YVYU,
157                 .depth              = 16,
158 @@ -87,6 +94,7 @@ static const struct bcm2835_isp_fmt supp
159                 .mmal_fmt           = MMAL_ENCODING_YVYU,
160                 .size_multiplier_x2 = 2,
161                 .colorspace         = V4L2_COLORSPACE_SMPTE170M,
162 +               .step_size          = 2,
163         }, {
164                 .fourcc             = V4L2_PIX_FMT_VYUY,
165                 .depth              = 16,
166 @@ -95,6 +103,7 @@ static const struct bcm2835_isp_fmt supp
167                 .mmal_fmt           = MMAL_ENCODING_VYUY,
168                 .size_multiplier_x2 = 2,
169                 .colorspace         = V4L2_COLORSPACE_SMPTE170M,
170 +               .step_size          = 2,
171         }, {
172                 /* RGB formats */
173                 .fourcc             = V4L2_PIX_FMT_RGB24,
174 @@ -104,6 +113,7 @@ static const struct bcm2835_isp_fmt supp
175                 .mmal_fmt           = MMAL_ENCODING_RGB24,
176                 .size_multiplier_x2 = 2,
177                 .colorspace         = V4L2_COLORSPACE_SRGB,
178 +               .step_size          = 1,
179         }, {
180                 .fourcc             = V4L2_PIX_FMT_RGB565,
181                 .depth              = 16,
182 @@ -112,6 +122,7 @@ static const struct bcm2835_isp_fmt supp
183                 .mmal_fmt           = MMAL_ENCODING_RGB16,
184                 .size_multiplier_x2 = 2,
185                 .colorspace         = V4L2_COLORSPACE_SRGB,
186 +               .step_size          = 1,
187         }, {
188                 .fourcc             = V4L2_PIX_FMT_BGR24,
189                 .depth              = 24,
190 @@ -120,6 +131,7 @@ static const struct bcm2835_isp_fmt supp
191                 .mmal_fmt           = MMAL_ENCODING_BGR24,
192                 .size_multiplier_x2 = 2,
193                 .colorspace         = V4L2_COLORSPACE_SRGB,
194 +               .step_size          = 1,
195         }, {
196                 .fourcc             = V4L2_PIX_FMT_ABGR32,
197                 .depth              = 32,
198 @@ -128,6 +140,7 @@ static const struct bcm2835_isp_fmt supp
199                 .mmal_fmt           = MMAL_ENCODING_BGRA,
200                 .size_multiplier_x2 = 2,
201                 .colorspace         = V4L2_COLORSPACE_SRGB,
202 +               .step_size          = 1,
203         }, {
204                 /* Bayer formats */
205                 /* 8 bit */
206 @@ -138,6 +151,7 @@ static const struct bcm2835_isp_fmt supp
207                 .mmal_fmt           = MMAL_ENCODING_BAYER_SRGGB8,
208                 .size_multiplier_x2 = 2,
209                 .colorspace         = V4L2_COLORSPACE_RAW,
210 +               .step_size          = 2,
211         }, {
212                 .fourcc             = V4L2_PIX_FMT_SBGGR8,
213                 .depth              = 8,
214 @@ -146,6 +160,7 @@ static const struct bcm2835_isp_fmt supp
215                 .mmal_fmt           = MMAL_ENCODING_BAYER_SBGGR8,
216                 .size_multiplier_x2 = 2,
217                 .colorspace         = V4L2_COLORSPACE_RAW,
218 +               .step_size          = 2,
219         }, {
220                 .fourcc             = V4L2_PIX_FMT_SGRBG8,
221                 .depth              = 8,
222 @@ -154,6 +169,7 @@ static const struct bcm2835_isp_fmt supp
223                 .mmal_fmt           = MMAL_ENCODING_BAYER_SGRBG8,
224                 .size_multiplier_x2 = 2,
225                 .colorspace         = V4L2_COLORSPACE_RAW,
226 +               .step_size          = 2,
227         }, {
228                 .fourcc             = V4L2_PIX_FMT_SGBRG8,
229                 .depth              = 8,
230 @@ -162,6 +178,7 @@ static const struct bcm2835_isp_fmt supp
231                 .mmal_fmt           = MMAL_ENCODING_BAYER_SGBRG8,
232                 .size_multiplier_x2 = 2,
233                 .colorspace         = V4L2_COLORSPACE_RAW,
234 +               .step_size          = 2,
235         }, {
236                 /* 10 bit */
237                 .fourcc             = V4L2_PIX_FMT_SRGGB10P,
238 @@ -171,6 +188,7 @@ static const struct bcm2835_isp_fmt supp
239                 .mmal_fmt           = MMAL_ENCODING_BAYER_SRGGB10P,
240                 .size_multiplier_x2 = 2,
241                 .colorspace         = V4L2_COLORSPACE_RAW,
242 +               .step_size          = 2,
243         }, {
244                 .fourcc             = V4L2_PIX_FMT_SBGGR10P,
245                 .depth              = 10,
246 @@ -179,6 +197,7 @@ static const struct bcm2835_isp_fmt supp
247                 .mmal_fmt           = MMAL_ENCODING_BAYER_SBGGR10P,
248                 .size_multiplier_x2 = 2,
249                 .colorspace         = V4L2_COLORSPACE_RAW,
250 +               .step_size          = 2,
251         }, {
252                 .fourcc             = V4L2_PIX_FMT_SGRBG10P,
253                 .depth              = 10,
254 @@ -187,6 +206,7 @@ static const struct bcm2835_isp_fmt supp
255                 .mmal_fmt           = MMAL_ENCODING_BAYER_SGRBG10P,
256                 .size_multiplier_x2 = 2,
257                 .colorspace         = V4L2_COLORSPACE_RAW,
258 +               .step_size          = 2,
259         }, {
260                 .fourcc             = V4L2_PIX_FMT_SGBRG10P,
261                 .depth              = 10,
262 @@ -195,6 +215,7 @@ static const struct bcm2835_isp_fmt supp
263                 .mmal_fmt           = MMAL_ENCODING_BAYER_SGBRG10P,
264                 .size_multiplier_x2 = 2,
265                 .colorspace         = V4L2_COLORSPACE_RAW,
266 +               .step_size          = 2,
267         }, {
268                 /* 12 bit */
269                 .fourcc             = V4L2_PIX_FMT_SRGGB12P,
270 @@ -204,6 +225,7 @@ static const struct bcm2835_isp_fmt supp
271                 .mmal_fmt           = MMAL_ENCODING_BAYER_SRGGB12P,
272                 .size_multiplier_x2 = 2,
273                 .colorspace         = V4L2_COLORSPACE_RAW,
274 +               .step_size          = 2,
275         }, {
276                 .fourcc             = V4L2_PIX_FMT_SBGGR12P,
277                 .depth              = 12,
278 @@ -212,6 +234,7 @@ static const struct bcm2835_isp_fmt supp
279                 .mmal_fmt           = MMAL_ENCODING_BAYER_SBGGR12P,
280                 .size_multiplier_x2 = 2,
281                 .colorspace         = V4L2_COLORSPACE_RAW,
282 +               .step_size          = 2,
283         }, {
284                 .fourcc             = V4L2_PIX_FMT_SGRBG12P,
285                 .depth              = 12,
286 @@ -220,6 +243,7 @@ static const struct bcm2835_isp_fmt supp
287                 .mmal_fmt           = MMAL_ENCODING_BAYER_SGRBG12P,
288                 .size_multiplier_x2 = 2,
289                 .colorspace         = V4L2_COLORSPACE_RAW,
290 +               .step_size          = 2,
291         }, {
292                 .fourcc             = V4L2_PIX_FMT_SGBRG12P,
293                 .depth              = 12,
294 @@ -228,6 +252,7 @@ static const struct bcm2835_isp_fmt supp
295                 .mmal_fmt           = MMAL_ENCODING_BAYER_SGBRG12P,
296                 .size_multiplier_x2 = 2,
297                 .colorspace         = V4L2_COLORSPACE_RAW,
298 +               .step_size          = 2,
299         }, {
300                 /* 16 bit */
301                 .fourcc             = V4L2_PIX_FMT_SRGGB16,
302 @@ -237,6 +262,7 @@ static const struct bcm2835_isp_fmt supp
303                 .mmal_fmt           = MMAL_ENCODING_BAYER_SRGGB16,
304                 .size_multiplier_x2 = 2,
305                 .colorspace         = V4L2_COLORSPACE_RAW,
306 +               .step_size          = 2,
307         }, {
308                 .fourcc             = V4L2_PIX_FMT_SBGGR16,
309                 .depth              = 16,
310 @@ -245,6 +271,7 @@ static const struct bcm2835_isp_fmt supp
311                 .mmal_fmt           = MMAL_ENCODING_BAYER_SBGGR16,
312                 .size_multiplier_x2 = 2,
313                 .colorspace         = V4L2_COLORSPACE_RAW,
314 +               .step_size          = 2,
315         }, {
316                 .fourcc             = V4L2_PIX_FMT_SGRBG16,
317                 .depth              = 16,
318 @@ -253,6 +280,7 @@ static const struct bcm2835_isp_fmt supp
319                 .mmal_fmt           = MMAL_ENCODING_BAYER_SGRBG16,
320                 .size_multiplier_x2 = 2,
321                 .colorspace         = V4L2_COLORSPACE_RAW,
322 +               .step_size          = 2,
323         }, {
324                 .fourcc             = V4L2_PIX_FMT_SGBRG16,
325                 .depth              = 16,
326 @@ -261,6 +289,7 @@ static const struct bcm2835_isp_fmt supp
327                 .mmal_fmt           = MMAL_ENCODING_BAYER_SGBRG16,
328                 .size_multiplier_x2 = 2,
329                 .colorspace         = V4L2_COLORSPACE_RAW,
330 +               .step_size          = 2,
331         }, {
332                 /* ISP statistics format */
333                 .fourcc             = V4L2_META_FMT_BCM2835_ISP_STATS,