f4f3218877451b1fa01f2cd6e29b819358921109
[openwrt/staging/ansuel.git] /
1 From 35534584af58ed5b953399fa5bfb0338c68258db Mon Sep 17 00:00:00 2001
2 From: David Plowman <david.plowman@raspberrypi.com>
3 Date: Tue, 12 Jan 2021 13:55:39 +0000
4 Subject: [PATCH] bcm2835-isp: Allow formats with different colour
5 spaces.
6
7 Each supported format now includes a mask showing the allowed colour
8 spaces, as well as a default colour space for when one was not
9 specified.
10
11 Additionally we translate the colour space to mmal format and pass it
12 over to the VideoCore.
13
14 Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
15 ---
16 .../bcm2835-isp/bcm2835-isp-fmts.h | 180 ++++++++++++------
17 .../bcm2835-isp/bcm2835-v4l2-isp.c | 66 ++++++-
18 2 files changed, 190 insertions(+), 56 deletions(-)
19
20 --- a/drivers/staging/vc04_services/bcm2835-isp/bcm2835-isp-fmts.h
21 +++ b/drivers/staging/vc04_services/bcm2835-isp/bcm2835-isp-fmts.h
22 @@ -20,10 +20,29 @@ struct bcm2835_isp_fmt {
23 int bytesperline_align;
24 u32 mmal_fmt;
25 int size_multiplier_x2;
26 - enum v4l2_colorspace colorspace;
27 + u32 colorspace_mask;
28 + enum v4l2_colorspace colorspace_default;
29 unsigned int step_size;
30 };
31
32 +#define V4L2_COLORSPACE_MASK(colorspace) BIT(colorspace)
33 +
34 +#define V4L2_COLORSPACE_MASK_JPEG V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_JPEG)
35 +#define V4L2_COLORSPACE_MASK_SMPTE170M V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_SMPTE170M)
36 +#define V4L2_COLORSPACE_MASK_REC709 V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_REC709)
37 +#define V4L2_COLORSPACE_MASK_SRGB V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_SRGB)
38 +#define V4L2_COLORSPACE_MASK_RAW V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_RAW)
39 +
40 +/*
41 + * The colour spaces we support for YUV outputs. SRGB features here because,
42 + * once you assign the default transfer func and so on, it and JPEG effectively
43 + * mean the same.
44 + */
45 +#define V4L2_COLORSPACE_MASK_YUV (V4L2_COLORSPACE_MASK_JPEG | \
46 + V4L2_COLORSPACE_MASK_SRGB | \
47 + V4L2_COLORSPACE_MASK_SMPTE170M | \
48 + V4L2_COLORSPACE_MASK_REC709)
49 +
50 static const struct bcm2835_isp_fmt supported_formats[] = {
51 {
52 /* YUV formats */
53 @@ -32,7 +51,8 @@ static const struct bcm2835_isp_fmt supp
54 .bytesperline_align = 32,
55 .mmal_fmt = MMAL_ENCODING_I420,
56 .size_multiplier_x2 = 3,
57 - .colorspace = V4L2_COLORSPACE_SMPTE170M,
58 + .colorspace_mask = V4L2_COLORSPACE_MASK_YUV,
59 + .colorspace_default = V4L2_COLORSPACE_JPEG,
60 .step_size = 2,
61 }, {
62 .fourcc = V4L2_PIX_FMT_YVU420,
63 @@ -40,7 +60,8 @@ static const struct bcm2835_isp_fmt supp
64 .bytesperline_align = 32,
65 .mmal_fmt = MMAL_ENCODING_YV12,
66 .size_multiplier_x2 = 3,
67 - .colorspace = V4L2_COLORSPACE_SMPTE170M,
68 + .colorspace_mask = V4L2_COLORSPACE_MASK_YUV,
69 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
70 .step_size = 2,
71 }, {
72 .fourcc = V4L2_PIX_FMT_NV12,
73 @@ -48,7 +69,8 @@ static const struct bcm2835_isp_fmt supp
74 .bytesperline_align = 32,
75 .mmal_fmt = MMAL_ENCODING_NV12,
76 .size_multiplier_x2 = 3,
77 - .colorspace = V4L2_COLORSPACE_SMPTE170M,
78 + .colorspace_mask = V4L2_COLORSPACE_MASK_YUV,
79 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
80 .step_size = 2,
81 }, {
82 .fourcc = V4L2_PIX_FMT_NV21,
83 @@ -56,7 +78,8 @@ static const struct bcm2835_isp_fmt supp
84 .bytesperline_align = 32,
85 .mmal_fmt = MMAL_ENCODING_NV21,
86 .size_multiplier_x2 = 3,
87 - .colorspace = V4L2_COLORSPACE_SMPTE170M,
88 + .colorspace_mask = V4L2_COLORSPACE_MASK_YUV,
89 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
90 .step_size = 2,
91 }, {
92 .fourcc = V4L2_PIX_FMT_YUYV,
93 @@ -64,7 +87,8 @@ static const struct bcm2835_isp_fmt supp
94 .bytesperline_align = 64,
95 .mmal_fmt = MMAL_ENCODING_YUYV,
96 .size_multiplier_x2 = 2,
97 - .colorspace = V4L2_COLORSPACE_SMPTE170M,
98 + .colorspace_mask = V4L2_COLORSPACE_MASK_YUV,
99 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
100 .step_size = 2,
101 }, {
102 .fourcc = V4L2_PIX_FMT_UYVY,
103 @@ -72,7 +96,8 @@ static const struct bcm2835_isp_fmt supp
104 .bytesperline_align = 64,
105 .mmal_fmt = MMAL_ENCODING_UYVY,
106 .size_multiplier_x2 = 2,
107 - .colorspace = V4L2_COLORSPACE_SMPTE170M,
108 + .colorspace_mask = V4L2_COLORSPACE_MASK_YUV,
109 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
110 .step_size = 2,
111 }, {
112 .fourcc = V4L2_PIX_FMT_YVYU,
113 @@ -80,7 +105,8 @@ static const struct bcm2835_isp_fmt supp
114 .bytesperline_align = 64,
115 .mmal_fmt = MMAL_ENCODING_YVYU,
116 .size_multiplier_x2 = 2,
117 - .colorspace = V4L2_COLORSPACE_SMPTE170M,
118 + .colorspace_mask = V4L2_COLORSPACE_MASK_YUV,
119 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
120 .step_size = 2,
121 }, {
122 .fourcc = V4L2_PIX_FMT_VYUY,
123 @@ -88,7 +114,8 @@ static const struct bcm2835_isp_fmt supp
124 .bytesperline_align = 64,
125 .mmal_fmt = MMAL_ENCODING_VYUY,
126 .size_multiplier_x2 = 2,
127 - .colorspace = V4L2_COLORSPACE_SMPTE170M,
128 + .colorspace_mask = V4L2_COLORSPACE_MASK_YUV,
129 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
130 .step_size = 2,
131 }, {
132 /* RGB formats */
133 @@ -97,7 +124,8 @@ static const struct bcm2835_isp_fmt supp
134 .bytesperline_align = 32,
135 .mmal_fmt = MMAL_ENCODING_RGB24,
136 .size_multiplier_x2 = 2,
137 - .colorspace = V4L2_COLORSPACE_SRGB,
138 + .colorspace_mask = V4L2_COLORSPACE_MASK_SRGB,
139 + .colorspace_default = V4L2_COLORSPACE_SRGB,
140 .step_size = 1,
141 }, {
142 .fourcc = V4L2_PIX_FMT_RGB565,
143 @@ -105,7 +133,8 @@ static const struct bcm2835_isp_fmt supp
144 .bytesperline_align = 32,
145 .mmal_fmt = MMAL_ENCODING_RGB16,
146 .size_multiplier_x2 = 2,
147 - .colorspace = V4L2_COLORSPACE_SRGB,
148 + .colorspace_mask = V4L2_COLORSPACE_MASK_SRGB,
149 + .colorspace_default = V4L2_COLORSPACE_SRGB,
150 .step_size = 1,
151 }, {
152 .fourcc = V4L2_PIX_FMT_BGR24,
153 @@ -113,7 +142,8 @@ static const struct bcm2835_isp_fmt supp
154 .bytesperline_align = 32,
155 .mmal_fmt = MMAL_ENCODING_BGR24,
156 .size_multiplier_x2 = 2,
157 - .colorspace = V4L2_COLORSPACE_SRGB,
158 + .colorspace_mask = V4L2_COLORSPACE_MASK_SRGB,
159 + .colorspace_default = V4L2_COLORSPACE_SRGB,
160 .step_size = 1,
161 }, {
162 .fourcc = V4L2_PIX_FMT_XBGR32,
163 @@ -121,7 +151,8 @@ static const struct bcm2835_isp_fmt supp
164 .bytesperline_align = 64,
165 .mmal_fmt = MMAL_ENCODING_BGRA,
166 .size_multiplier_x2 = 2,
167 - .colorspace = V4L2_COLORSPACE_SRGB,
168 + .colorspace_mask = V4L2_COLORSPACE_MASK_SRGB,
169 + .colorspace_default = V4L2_COLORSPACE_SRGB,
170 .step_size = 1,
171 }, {
172 .fourcc = V4L2_PIX_FMT_RGBX32,
173 @@ -129,7 +160,8 @@ static const struct bcm2835_isp_fmt supp
174 .bytesperline_align = 64,
175 .mmal_fmt = MMAL_ENCODING_RGBA,
176 .size_multiplier_x2 = 2,
177 - .colorspace = V4L2_COLORSPACE_SRGB,
178 + .colorspace_mask = V4L2_COLORSPACE_MASK_SRGB,
179 + .colorspace_default = V4L2_COLORSPACE_SRGB,
180 .step_size = 1,
181 }, {
182 /* Bayer formats */
183 @@ -139,7 +171,8 @@ static const struct bcm2835_isp_fmt supp
184 .bytesperline_align = 32,
185 .mmal_fmt = MMAL_ENCODING_BAYER_SRGGB8,
186 .size_multiplier_x2 = 2,
187 - .colorspace = V4L2_COLORSPACE_RAW,
188 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
189 + .colorspace_default = V4L2_COLORSPACE_RAW,
190 .step_size = 2,
191 }, {
192 .fourcc = V4L2_PIX_FMT_SBGGR8,
193 @@ -147,7 +180,8 @@ static const struct bcm2835_isp_fmt supp
194 .bytesperline_align = 32,
195 .mmal_fmt = MMAL_ENCODING_BAYER_SBGGR8,
196 .size_multiplier_x2 = 2,
197 - .colorspace = V4L2_COLORSPACE_RAW,
198 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
199 + .colorspace_default = V4L2_COLORSPACE_RAW,
200 .step_size = 2,
201 }, {
202 .fourcc = V4L2_PIX_FMT_SGRBG8,
203 @@ -155,7 +189,8 @@ static const struct bcm2835_isp_fmt supp
204 .bytesperline_align = 32,
205 .mmal_fmt = MMAL_ENCODING_BAYER_SGRBG8,
206 .size_multiplier_x2 = 2,
207 - .colorspace = V4L2_COLORSPACE_RAW,
208 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
209 + .colorspace_default = V4L2_COLORSPACE_RAW,
210 .step_size = 2,
211 }, {
212 .fourcc = V4L2_PIX_FMT_SGBRG8,
213 @@ -163,7 +198,8 @@ static const struct bcm2835_isp_fmt supp
214 .bytesperline_align = 32,
215 .mmal_fmt = MMAL_ENCODING_BAYER_SGBRG8,
216 .size_multiplier_x2 = 2,
217 - .colorspace = V4L2_COLORSPACE_RAW,
218 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
219 + .colorspace_default = V4L2_COLORSPACE_RAW,
220 .step_size = 2,
221 }, {
222 /* 10 bit */
223 @@ -172,7 +208,8 @@ static const struct bcm2835_isp_fmt supp
224 .bytesperline_align = 32,
225 .mmal_fmt = MMAL_ENCODING_BAYER_SRGGB10P,
226 .size_multiplier_x2 = 2,
227 - .colorspace = V4L2_COLORSPACE_RAW,
228 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
229 + .colorspace_default = V4L2_COLORSPACE_RAW,
230 .step_size = 2,
231 }, {
232 .fourcc = V4L2_PIX_FMT_SBGGR10P,
233 @@ -180,7 +217,8 @@ static const struct bcm2835_isp_fmt supp
234 .bytesperline_align = 32,
235 .mmal_fmt = MMAL_ENCODING_BAYER_SBGGR10P,
236 .size_multiplier_x2 = 2,
237 - .colorspace = V4L2_COLORSPACE_RAW,
238 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
239 + .colorspace_default = V4L2_COLORSPACE_RAW,
240 .step_size = 2,
241 }, {
242 .fourcc = V4L2_PIX_FMT_SGRBG10P,
243 @@ -188,7 +226,8 @@ static const struct bcm2835_isp_fmt supp
244 .bytesperline_align = 32,
245 .mmal_fmt = MMAL_ENCODING_BAYER_SGRBG10P,
246 .size_multiplier_x2 = 2,
247 - .colorspace = V4L2_COLORSPACE_RAW,
248 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
249 + .colorspace_default = V4L2_COLORSPACE_RAW,
250 .step_size = 2,
251 }, {
252 .fourcc = V4L2_PIX_FMT_SGBRG10P,
253 @@ -196,7 +235,8 @@ static const struct bcm2835_isp_fmt supp
254 .bytesperline_align = 32,
255 .mmal_fmt = MMAL_ENCODING_BAYER_SGBRG10P,
256 .size_multiplier_x2 = 2,
257 - .colorspace = V4L2_COLORSPACE_RAW,
258 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
259 + .colorspace_default = V4L2_COLORSPACE_RAW,
260 .step_size = 2,
261 }, {
262 /* 12 bit */
263 @@ -205,7 +245,8 @@ static const struct bcm2835_isp_fmt supp
264 .bytesperline_align = 32,
265 .mmal_fmt = MMAL_ENCODING_BAYER_SRGGB12P,
266 .size_multiplier_x2 = 2,
267 - .colorspace = V4L2_COLORSPACE_RAW,
268 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
269 + .colorspace_default = V4L2_COLORSPACE_RAW,
270 .step_size = 2,
271 }, {
272 .fourcc = V4L2_PIX_FMT_SBGGR12P,
273 @@ -213,7 +254,8 @@ static const struct bcm2835_isp_fmt supp
274 .bytesperline_align = 32,
275 .mmal_fmt = MMAL_ENCODING_BAYER_SBGGR12P,
276 .size_multiplier_x2 = 2,
277 - .colorspace = V4L2_COLORSPACE_RAW,
278 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
279 + .colorspace_default = V4L2_COLORSPACE_RAW,
280 .step_size = 2,
281 }, {
282 .fourcc = V4L2_PIX_FMT_SGRBG12P,
283 @@ -221,7 +263,8 @@ static const struct bcm2835_isp_fmt supp
284 .bytesperline_align = 32,
285 .mmal_fmt = MMAL_ENCODING_BAYER_SGRBG12P,
286 .size_multiplier_x2 = 2,
287 - .colorspace = V4L2_COLORSPACE_RAW,
288 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
289 + .colorspace_default = V4L2_COLORSPACE_RAW,
290 .step_size = 2,
291 }, {
292 .fourcc = V4L2_PIX_FMT_SGBRG12P,
293 @@ -229,7 +272,8 @@ static const struct bcm2835_isp_fmt supp
294 .bytesperline_align = 32,
295 .mmal_fmt = MMAL_ENCODING_BAYER_SGBRG12P,
296 .size_multiplier_x2 = 2,
297 - .colorspace = V4L2_COLORSPACE_RAW,
298 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
299 + .colorspace_default = V4L2_COLORSPACE_RAW,
300 .step_size = 2,
301 }, {
302 /* 14 bit */
303 @@ -238,7 +282,8 @@ static const struct bcm2835_isp_fmt supp
304 .bytesperline_align = 32,
305 .mmal_fmt = MMAL_ENCODING_BAYER_SRGGB14P,
306 .size_multiplier_x2 = 2,
307 - .colorspace = V4L2_COLORSPACE_RAW,
308 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
309 + .colorspace_default = V4L2_COLORSPACE_RAW,
310 .step_size = 2,
311 }, {
312 .fourcc = V4L2_PIX_FMT_SBGGR14P,
313 @@ -246,7 +291,8 @@ static const struct bcm2835_isp_fmt supp
314 .bytesperline_align = 32,
315 .mmal_fmt = MMAL_ENCODING_BAYER_SBGGR14P,
316 .size_multiplier_x2 = 2,
317 - .colorspace = V4L2_COLORSPACE_RAW,
318 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
319 + .colorspace_default = V4L2_COLORSPACE_RAW,
320 .step_size = 2,
321 }, {
322 .fourcc = V4L2_PIX_FMT_SGRBG14P,
323 @@ -254,7 +300,8 @@ static const struct bcm2835_isp_fmt supp
324 .bytesperline_align = 32,
325 .mmal_fmt = MMAL_ENCODING_BAYER_SGRBG14P,
326 .size_multiplier_x2 = 2,
327 - .colorspace = V4L2_COLORSPACE_RAW,
328 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
329 + .colorspace_default = V4L2_COLORSPACE_RAW,
330 .step_size = 2,
331 }, {
332 .fourcc = V4L2_PIX_FMT_SGBRG14P,
333 @@ -262,7 +309,8 @@ static const struct bcm2835_isp_fmt supp
334 .bytesperline_align = 32,
335 .mmal_fmt = MMAL_ENCODING_BAYER_SGBRG14P,
336 .size_multiplier_x2 = 2,
337 - .colorspace = V4L2_COLORSPACE_RAW,
338 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
339 + .colorspace_default = V4L2_COLORSPACE_RAW,
340 .step_size = 2,
341 }, {
342 /* 16 bit */
343 @@ -271,7 +319,8 @@ static const struct bcm2835_isp_fmt supp
344 .bytesperline_align = 32,
345 .mmal_fmt = MMAL_ENCODING_BAYER_SRGGB16,
346 .size_multiplier_x2 = 2,
347 - .colorspace = V4L2_COLORSPACE_RAW,
348 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
349 + .colorspace_default = V4L2_COLORSPACE_RAW,
350 .step_size = 2,
351 }, {
352 .fourcc = V4L2_PIX_FMT_SBGGR16,
353 @@ -279,7 +328,8 @@ static const struct bcm2835_isp_fmt supp
354 .bytesperline_align = 32,
355 .mmal_fmt = MMAL_ENCODING_BAYER_SBGGR16,
356 .size_multiplier_x2 = 2,
357 - .colorspace = V4L2_COLORSPACE_RAW,
358 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
359 + .colorspace_default = V4L2_COLORSPACE_RAW,
360 .step_size = 2,
361 }, {
362 .fourcc = V4L2_PIX_FMT_SGRBG16,
363 @@ -287,7 +337,8 @@ static const struct bcm2835_isp_fmt supp
364 .bytesperline_align = 32,
365 .mmal_fmt = MMAL_ENCODING_BAYER_SGRBG16,
366 .size_multiplier_x2 = 2,
367 - .colorspace = V4L2_COLORSPACE_RAW,
368 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
369 + .colorspace_default = V4L2_COLORSPACE_RAW,
370 .step_size = 2,
371 }, {
372 .fourcc = V4L2_PIX_FMT_SGBRG16,
373 @@ -295,7 +346,8 @@ static const struct bcm2835_isp_fmt supp
374 .bytesperline_align = 32,
375 .mmal_fmt = MMAL_ENCODING_BAYER_SGBRG16,
376 .size_multiplier_x2 = 2,
377 - .colorspace = V4L2_COLORSPACE_RAW,
378 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
379 + .colorspace_default = V4L2_COLORSPACE_RAW,
380 .step_size = 2,
381 }, {
382 /* Bayer formats unpacked to 16bpp */
383 @@ -305,7 +357,8 @@ static const struct bcm2835_isp_fmt supp
384 .bytesperline_align = 32,
385 .mmal_fmt = MMAL_ENCODING_BAYER_SRGGB10,
386 .size_multiplier_x2 = 2,
387 - .colorspace = V4L2_COLORSPACE_RAW,
388 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
389 + .colorspace_default = V4L2_COLORSPACE_RAW,
390 .step_size = 2,
391 }, {
392 .fourcc = V4L2_PIX_FMT_SBGGR10,
393 @@ -313,7 +366,8 @@ static const struct bcm2835_isp_fmt supp
394 .bytesperline_align = 32,
395 .mmal_fmt = MMAL_ENCODING_BAYER_SBGGR10,
396 .size_multiplier_x2 = 2,
397 - .colorspace = V4L2_COLORSPACE_RAW,
398 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
399 + .colorspace_default = V4L2_COLORSPACE_RAW,
400 .step_size = 2,
401 }, {
402 .fourcc = V4L2_PIX_FMT_SGRBG10,
403 @@ -321,7 +375,8 @@ static const struct bcm2835_isp_fmt supp
404 .bytesperline_align = 32,
405 .mmal_fmt = MMAL_ENCODING_BAYER_SGRBG10,
406 .size_multiplier_x2 = 2,
407 - .colorspace = V4L2_COLORSPACE_RAW,
408 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
409 + .colorspace_default = V4L2_COLORSPACE_RAW,
410 .step_size = 2,
411 }, {
412 .fourcc = V4L2_PIX_FMT_SGBRG10,
413 @@ -329,7 +384,8 @@ static const struct bcm2835_isp_fmt supp
414 .bytesperline_align = 32,
415 .mmal_fmt = MMAL_ENCODING_BAYER_SGBRG10,
416 .size_multiplier_x2 = 2,
417 - .colorspace = V4L2_COLORSPACE_RAW,
418 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
419 + .colorspace_default = V4L2_COLORSPACE_RAW,
420 .step_size = 2,
421 }, {
422 /* 12 bit */
423 @@ -338,7 +394,8 @@ static const struct bcm2835_isp_fmt supp
424 .bytesperline_align = 32,
425 .mmal_fmt = MMAL_ENCODING_BAYER_SRGGB12,
426 .size_multiplier_x2 = 2,
427 - .colorspace = V4L2_COLORSPACE_RAW,
428 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
429 + .colorspace_default = V4L2_COLORSPACE_RAW,
430 .step_size = 2,
431 }, {
432 .fourcc = V4L2_PIX_FMT_SBGGR12,
433 @@ -346,7 +403,8 @@ static const struct bcm2835_isp_fmt supp
434 .bytesperline_align = 32,
435 .mmal_fmt = MMAL_ENCODING_BAYER_SBGGR12,
436 .size_multiplier_x2 = 2,
437 - .colorspace = V4L2_COLORSPACE_RAW,
438 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
439 + .colorspace_default = V4L2_COLORSPACE_RAW,
440 .step_size = 2,
441 }, {
442 .fourcc = V4L2_PIX_FMT_SGRBG12,
443 @@ -354,7 +412,8 @@ static const struct bcm2835_isp_fmt supp
444 .bytesperline_align = 32,
445 .mmal_fmt = MMAL_ENCODING_BAYER_SGRBG12,
446 .size_multiplier_x2 = 2,
447 - .colorspace = V4L2_COLORSPACE_RAW,
448 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
449 + .colorspace_default = V4L2_COLORSPACE_RAW,
450 .step_size = 2,
451 }, {
452 .fourcc = V4L2_PIX_FMT_SGBRG12,
453 @@ -362,7 +421,8 @@ static const struct bcm2835_isp_fmt supp
454 .bytesperline_align = 32,
455 .mmal_fmt = MMAL_ENCODING_BAYER_SGBRG12,
456 .size_multiplier_x2 = 2,
457 - .colorspace = V4L2_COLORSPACE_RAW,
458 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
459 + .colorspace_default = V4L2_COLORSPACE_RAW,
460 .step_size = 2,
461 }, {
462 /* 14 bit */
463 @@ -371,7 +431,8 @@ static const struct bcm2835_isp_fmt supp
464 .bytesperline_align = 32,
465 .mmal_fmt = MMAL_ENCODING_BAYER_SRGGB14,
466 .size_multiplier_x2 = 2,
467 - .colorspace = V4L2_COLORSPACE_RAW,
468 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
469 + .colorspace_default = V4L2_COLORSPACE_RAW,
470 .step_size = 2,
471 }, {
472 .fourcc = V4L2_PIX_FMT_SBGGR14,
473 @@ -379,7 +440,8 @@ static const struct bcm2835_isp_fmt supp
474 .bytesperline_align = 32,
475 .mmal_fmt = MMAL_ENCODING_BAYER_SBGGR14,
476 .size_multiplier_x2 = 2,
477 - .colorspace = V4L2_COLORSPACE_RAW,
478 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
479 + .colorspace_default = V4L2_COLORSPACE_RAW,
480 .step_size = 2,
481 }, {
482 .fourcc = V4L2_PIX_FMT_SGRBG14,
483 @@ -387,7 +449,8 @@ static const struct bcm2835_isp_fmt supp
484 .bytesperline_align = 32,
485 .mmal_fmt = MMAL_ENCODING_BAYER_SGRBG14,
486 .size_multiplier_x2 = 2,
487 - .colorspace = V4L2_COLORSPACE_RAW,
488 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
489 + .colorspace_default = V4L2_COLORSPACE_RAW,
490 .step_size = 2,
491 }, {
492 .fourcc = V4L2_PIX_FMT_SGBRG14,
493 @@ -395,7 +458,8 @@ static const struct bcm2835_isp_fmt supp
494 .bytesperline_align = 32,
495 .mmal_fmt = MMAL_ENCODING_BAYER_SGBRG14,
496 .size_multiplier_x2 = 2,
497 - .colorspace = V4L2_COLORSPACE_RAW,
498 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
499 + .colorspace_default = V4L2_COLORSPACE_RAW,
500 .step_size = 2,
501 }, {
502 /* Monochrome MIPI formats */
503 @@ -405,7 +469,8 @@ static const struct bcm2835_isp_fmt supp
504 .bytesperline_align = 32,
505 .mmal_fmt = MMAL_ENCODING_GREY,
506 .size_multiplier_x2 = 2,
507 - .colorspace = V4L2_COLORSPACE_RAW,
508 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
509 + .colorspace_default = V4L2_COLORSPACE_RAW,
510 .step_size = 2,
511 }, {
512 /* 10 bit */
513 @@ -414,7 +479,8 @@ static const struct bcm2835_isp_fmt supp
514 .bytesperline_align = 32,
515 .mmal_fmt = MMAL_ENCODING_Y10P,
516 .size_multiplier_x2 = 2,
517 - .colorspace = V4L2_COLORSPACE_RAW,
518 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
519 + .colorspace_default = V4L2_COLORSPACE_RAW,
520 .step_size = 2,
521 }, {
522 /* 12 bit */
523 @@ -423,7 +489,8 @@ static const struct bcm2835_isp_fmt supp
524 .bytesperline_align = 32,
525 .mmal_fmt = MMAL_ENCODING_Y12P,
526 .size_multiplier_x2 = 2,
527 - .colorspace = V4L2_COLORSPACE_RAW,
528 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
529 + .colorspace_default = V4L2_COLORSPACE_RAW,
530 .step_size = 2,
531 }, {
532 /* 14 bit */
533 @@ -432,7 +499,8 @@ static const struct bcm2835_isp_fmt supp
534 .bytesperline_align = 32,
535 .mmal_fmt = MMAL_ENCODING_Y14P,
536 .size_multiplier_x2 = 2,
537 - .colorspace = V4L2_COLORSPACE_RAW,
538 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
539 + .colorspace_default = V4L2_COLORSPACE_RAW,
540 .step_size = 2,
541 }, {
542 /* 16 bit */
543 @@ -441,7 +509,8 @@ static const struct bcm2835_isp_fmt supp
544 .bytesperline_align = 32,
545 .mmal_fmt = MMAL_ENCODING_Y16,
546 .size_multiplier_x2 = 2,
547 - .colorspace = V4L2_COLORSPACE_RAW,
548 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
549 + .colorspace_default = V4L2_COLORSPACE_RAW,
550 .step_size = 2,
551 }, {
552 /* 10 bit as 16bpp */
553 @@ -450,7 +519,8 @@ static const struct bcm2835_isp_fmt supp
554 .bytesperline_align = 32,
555 .mmal_fmt = MMAL_ENCODING_Y10,
556 .size_multiplier_x2 = 2,
557 - .colorspace = V4L2_COLORSPACE_RAW,
558 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
559 + .colorspace_default = V4L2_COLORSPACE_RAW,
560 .step_size = 2,
561 }, {
562 /* 12 bit as 16bpp */
563 @@ -459,7 +529,8 @@ static const struct bcm2835_isp_fmt supp
564 .bytesperline_align = 32,
565 .mmal_fmt = MMAL_ENCODING_Y12,
566 .size_multiplier_x2 = 2,
567 - .colorspace = V4L2_COLORSPACE_RAW,
568 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
569 + .colorspace_default = V4L2_COLORSPACE_RAW,
570 .step_size = 2,
571 }, {
572 /* 14 bit as 16bpp */
573 @@ -468,7 +539,8 @@ static const struct bcm2835_isp_fmt supp
574 .bytesperline_align = 32,
575 .mmal_fmt = MMAL_ENCODING_Y14,
576 .size_multiplier_x2 = 2,
577 - .colorspace = V4L2_COLORSPACE_RAW,
578 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
579 + .colorspace_default = V4L2_COLORSPACE_RAW,
580 .step_size = 2,
581 }, {
582 .fourcc = V4L2_META_FMT_BCM2835_ISP_STATS,
583 --- a/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
584 +++ b/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
585 @@ -74,6 +74,7 @@ struct bcm2835_isp_q_data {
586 unsigned int width;
587 unsigned int height;
588 unsigned int sizeimage;
589 + enum v4l2_colorspace colorspace;
590 const struct bcm2835_isp_fmt *fmt;
591 };
592
593 @@ -313,6 +314,43 @@ static void mmal_buffer_cb(struct vchiq_
594 complete(&dev->frame_cmplt);
595 }
596
597 +struct colorspace_translation {
598 + enum v4l2_colorspace v4l2_value;
599 + u32 mmal_value;
600 +};
601 +
602 +static u32 translate_color_space(enum v4l2_colorspace color_space)
603 +{
604 + static const struct colorspace_translation translations[] = {
605 + { V4L2_COLORSPACE_DEFAULT, MMAL_COLOR_SPACE_UNKNOWN },
606 + { V4L2_COLORSPACE_SMPTE170M, MMAL_COLOR_SPACE_ITUR_BT601 },
607 + { V4L2_COLORSPACE_SMPTE240M, MMAL_COLOR_SPACE_SMPTE240M },
608 + { V4L2_COLORSPACE_REC709, MMAL_COLOR_SPACE_ITUR_BT709 },
609 + /* V4L2_COLORSPACE_BT878 unavailable */
610 + { V4L2_COLORSPACE_470_SYSTEM_M, MMAL_COLOR_SPACE_BT470_2_M },
611 + { V4L2_COLORSPACE_470_SYSTEM_BG, MMAL_COLOR_SPACE_BT470_2_BG },
612 + { V4L2_COLORSPACE_JPEG, MMAL_COLOR_SPACE_JPEG_JFIF },
613 + /*
614 + * We don't have an encoding for SRGB as such, but VideoCore
615 + * will do the right thing if it gets "unknown".
616 + */
617 + { V4L2_COLORSPACE_SRGB, MMAL_COLOR_SPACE_UNKNOWN },
618 + /* V4L2_COLORSPACE_OPRGB unavailable */
619 + /* V4L2_COLORSPACE_BT2020 unavailable */
620 + /* V4L2_COLORSPACE_RAW unavailable */
621 + /* V4L2_COLORSPACE_DCI_P3 unavailable */
622 + };
623 +
624 + unsigned int i;
625 +
626 + for (i = 0; i < ARRAY_SIZE(translations); i++) {
627 + if (color_space == translations[i].v4l2_value)
628 + return translations[i].mmal_value;
629 + }
630 +
631 + return MMAL_COLOR_SPACE_UNKNOWN;
632 +}
633 +
634 static void setup_mmal_port_format(struct bcm2835_isp_node *node,
635 struct vchiq_mmal_port *port)
636 {
637 @@ -326,6 +364,7 @@ static void setup_mmal_port_format(struc
638 port->es.video.crop.height = q_data->height;
639 port->es.video.crop.x = 0;
640 port->es.video.crop.y = 0;
641 + port->es.video.color_space = translate_color_space(q_data->colorspace);
642 };
643
644 static int setup_mmal_port(struct bcm2835_isp_node *node)
645 @@ -829,6 +868,9 @@ static int populate_qdata_fmt(struct v4l
646 /* All parameters should have been set correctly by try_fmt */
647 q_data->bytesperline = f->fmt.pix.bytesperline;
648 q_data->sizeimage = f->fmt.pix.sizeimage;
649 +
650 + /* We must indicate which of the allowed colour spaces we have. */
651 + q_data->colorspace = f->fmt.pix.colorspace;
652 } else {
653 v4l2_dbg(1, debug, &dev->v4l2_dev,
654 "%s: Setting meta format for fmt: %08x, size %u\n",
655 @@ -840,6 +882,9 @@ static int populate_qdata_fmt(struct v4l
656 q_data->height = 0;
657 q_data->bytesperline = 0;
658 q_data->sizeimage = f->fmt.meta.buffersize;
659 +
660 + /* This won't mean anything for metadata, but may as well fill it in. */
661 + q_data->colorspace = V4L2_COLORSPACE_DEFAULT;
662 }
663
664 v4l2_dbg(1, debug, &dev->v4l2_dev,
665 @@ -903,7 +948,7 @@ static int bcm2835_isp_node_g_fmt(struct
666 f->fmt.pix.pixelformat = q_data->fmt->fourcc;
667 f->fmt.pix.bytesperline = q_data->bytesperline;
668 f->fmt.pix.sizeimage = q_data->sizeimage;
669 - f->fmt.pix.colorspace = q_data->fmt->colorspace;
670 + f->fmt.pix.colorspace = q_data->colorspace;
671 }
672
673 return 0;
674 @@ -970,13 +1015,29 @@ static int bcm2835_isp_node_try_fmt(stru
675 fmt = get_default_format(node);
676
677 if (!node_is_stats(node)) {
678 + int is_rgb;
679 +
680 f->fmt.pix.width = max(min(f->fmt.pix.width, MAX_DIM),
681 MIN_DIM);
682 f->fmt.pix.height = max(min(f->fmt.pix.height, MAX_DIM),
683 MIN_DIM);
684
685 f->fmt.pix.pixelformat = fmt->fourcc;
686 - f->fmt.pix.colorspace = fmt->colorspace;
687 +
688 + /*
689 + * Fill in the actual colour space when the requested one was
690 + * not supported. This also catches the case when the "default"
691 + * colour space was requested (as that's never in the mask).
692 + */
693 + if (!(V4L2_COLORSPACE_MASK(f->fmt.pix.colorspace) & fmt->colorspace_mask))
694 + f->fmt.pix.colorspace = fmt->colorspace_default;
695 + /* In all cases, we only support the defaults for these: */
696 + f->fmt.pix.ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(f->fmt.pix.colorspace);
697 + f->fmt.pix.xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(f->fmt.pix.colorspace);
698 + is_rgb = f->fmt.pix.colorspace == V4L2_COLORSPACE_SRGB;
699 + f->fmt.pix.quantization = V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb, f->fmt.pix.colorspace,
700 + f->fmt.pix.ycbcr_enc);
701 +
702 f->fmt.pix.bytesperline = get_bytesperline(f->fmt.pix.width,
703 fmt);
704 f->fmt.pix.field = V4L2_FIELD_NONE;
705 @@ -1301,6 +1362,7 @@ static int register_node(struct bcm2835_
706 node->q_data.width,
707 node->q_data.height,
708 node->q_data.fmt);
709 + node->q_data.colorspace = node->q_data.fmt->colorspace_default;
710
711 queue->io_modes = VB2_MMAP | VB2_DMABUF;
712 queue->drv_priv = node;