1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * PiSP Back End driver image format definitions.
4  *
5  * Copyright (c) 2021-2024 Raspberry Pi Ltd
6  */
7 
8 #ifndef _PISP_BE_FORMATS_
9 #define _PISP_BE_FORMATS_
10 
11 #include <linux/bits.h>
12 #include <linux/videodev2.h>
13 
14 #define PISPBE_MAX_PLANES	3
15 #define P3(x)			((x) * 8)
16 
17 struct pisp_be_format {
18 	unsigned int fourcc;
19 	unsigned int align;
20 	unsigned int bit_depth;
21 	/* 0P3 factor for plane sizing */
22 	unsigned int plane_factor[PISPBE_MAX_PLANES];
23 	unsigned int num_planes;
24 	unsigned int colorspace_mask;
25 	enum v4l2_colorspace colorspace_default;
26 };
27 
28 #define V4L2_COLORSPACE_MASK(colorspace) BIT(colorspace)
29 
30 #define V4L2_COLORSPACE_MASK_JPEG	\
31 	V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_JPEG)
32 #define V4L2_COLORSPACE_MASK_SMPTE170M	\
33 	V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_SMPTE170M)
34 #define V4L2_COLORSPACE_MASK_REC709	\
35 	V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_REC709)
36 #define V4L2_COLORSPACE_MASK_SRGB	\
37 	V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_SRGB)
38 #define V4L2_COLORSPACE_MASK_RAW	\
39 	V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_RAW)
40 
41 /*
42  * All three colour spaces SRGB, SMPTE170M and REC709 are fundamentally sRGB
43  * underneath (as near as makes no difference to us), just with different YCbCr
44  * encodings. Therefore the ISP can generate sRGB on its main output and any of
45  * the others on its low resolution output. Applications should, when using both
46  * outputs, program the colour spaces on them to be the same, matching whatever
47  * is requested for the low resolution output, even if the main output is
48  * producing an RGB format. In turn this requires us to allow all these colour
49  * spaces for every YUV/RGB output format.
50  */
51 #define V4L2_COLORSPACE_MASK_ALL_SRGB (V4L2_COLORSPACE_MASK_JPEG	| \
52 				       V4L2_COLORSPACE_MASK_SRGB	| \
53 				       V4L2_COLORSPACE_MASK_SMPTE170M	| \
54 				       V4L2_COLORSPACE_MASK_REC709)
55 
56 static const struct pisp_be_format supported_formats[] = {
57 	/* Single plane YUV formats */
58 	{
59 		.fourcc		    = V4L2_PIX_FMT_YUV420,
60 		/* 128 alignment to ensure U/V planes are 64 byte aligned. */
61 		.align		    = 128,
62 		.bit_depth	    = 8,
63 		.plane_factor	    = { P3(1), P3(0.25), P3(0.25) },
64 		.num_planes	    = 1,
65 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
66 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
67 	},
68 	{
69 		.fourcc		    = V4L2_PIX_FMT_YVU420,
70 		/* 128 alignment to ensure U/V planes are 64 byte aligned. */
71 		.align		    = 128,
72 		.bit_depth	    = 8,
73 		.plane_factor	    = { P3(1), P3(0.25), P3(0.25) },
74 		.num_planes	    = 1,
75 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
76 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
77 	},
78 	{
79 		.fourcc		    = V4L2_PIX_FMT_NV12,
80 		.align		    = 32,
81 		.bit_depth	    = 8,
82 		.plane_factor	    = { P3(1), P3(0.5) },
83 		.num_planes	    = 1,
84 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
85 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
86 	},
87 	{
88 		.fourcc		    = V4L2_PIX_FMT_NV21,
89 		.align		    = 32,
90 		.bit_depth	    = 8,
91 		.plane_factor	    = { P3(1), P3(0.5) },
92 		.num_planes	    = 1,
93 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
94 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
95 	},
96 	{
97 		.fourcc		    = V4L2_PIX_FMT_YUYV,
98 		.align		    = 64,
99 		.bit_depth	    = 16,
100 		.plane_factor	    = { P3(1) },
101 		.num_planes	    = 1,
102 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
103 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
104 	},
105 	{
106 		.fourcc		    = V4L2_PIX_FMT_UYVY,
107 		.align		    = 64,
108 		.bit_depth	    = 16,
109 		.plane_factor	    = { P3(1) },
110 		.num_planes	    = 1,
111 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
112 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
113 	},
114 	{
115 		.fourcc		    = V4L2_PIX_FMT_YVYU,
116 		.align		    = 64,
117 		.bit_depth	    = 16,
118 		.plane_factor	    = { P3(1) },
119 		.num_planes	    = 1,
120 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
121 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
122 	},
123 	{
124 		.fourcc		    = V4L2_PIX_FMT_VYUY,
125 		.align		    = 64,
126 		.bit_depth	    = 16,
127 		.plane_factor	    = { P3(1) },
128 		.num_planes	    = 1,
129 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
130 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
131 	},
132 	/* Multiplane YUV formats */
133 	{
134 		.fourcc		    = V4L2_PIX_FMT_YUV420M,
135 		.align		    = 64,
136 		.bit_depth	    = 8,
137 		.plane_factor	    = { P3(1), P3(0.25), P3(0.25) },
138 		.num_planes	    = 3,
139 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
140 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
141 	},
142 	{
143 		.fourcc		    = V4L2_PIX_FMT_NV12M,
144 		.align		    = 32,
145 		.bit_depth	    = 8,
146 		.plane_factor	    = { P3(1), P3(0.5) },
147 		.num_planes	    = 2,
148 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
149 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
150 	},
151 	{
152 		.fourcc		    = V4L2_PIX_FMT_NV21M,
153 		.align		    = 32,
154 		.bit_depth	    = 8,
155 		.plane_factor	    = { P3(1), P3(0.5) },
156 		.num_planes	    = 2,
157 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
158 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
159 	},
160 	{
161 		.fourcc		    = V4L2_PIX_FMT_YVU420M,
162 		.align		    = 64,
163 		.bit_depth	    = 8,
164 		.plane_factor	    = { P3(1), P3(0.25), P3(0.25) },
165 		.num_planes	    = 3,
166 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
167 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
168 	},
169 	{
170 		.fourcc		    = V4L2_PIX_FMT_YUV422M,
171 		.align		    = 64,
172 		.bit_depth	    = 8,
173 		.plane_factor	    = { P3(1), P3(0.5), P3(0.5) },
174 		.num_planes	    = 3,
175 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
176 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
177 	},
178 	{
179 		.fourcc		    = V4L2_PIX_FMT_YVU422M,
180 		.align		    = 64,
181 		.bit_depth	    = 8,
182 		.plane_factor	    = { P3(1), P3(0.5), P3(0.5) },
183 		.num_planes	    = 3,
184 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
185 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
186 	},
187 	{
188 		.fourcc		    = V4L2_PIX_FMT_YUV444M,
189 		.align		    = 64,
190 		.bit_depth	    = 8,
191 		.plane_factor	    = { P3(1), P3(1), P3(1) },
192 		.num_planes	    = 3,
193 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
194 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
195 	},
196 	{
197 		.fourcc		    = V4L2_PIX_FMT_YVU444M,
198 		.align		    = 64,
199 		.bit_depth	    = 8,
200 		.plane_factor	    = { P3(1), P3(1), P3(1) },
201 		.num_planes	    = 3,
202 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
203 		.colorspace_default = V4L2_COLORSPACE_SMPTE170M,
204 	},
205 	/* RGB formats */
206 	{
207 		.fourcc		    = V4L2_PIX_FMT_RGB24,
208 		.align		    = 32,
209 		.bit_depth	    = 24,
210 		.plane_factor	    = { P3(1.0) },
211 		.num_planes	    = 1,
212 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
213 		.colorspace_default = V4L2_COLORSPACE_SRGB,
214 	},
215 	{
216 		.fourcc		    = V4L2_PIX_FMT_BGR24,
217 		.align		    = 32,
218 		.bit_depth	    = 24,
219 		.plane_factor	    = { P3(1.0) },
220 		.num_planes	    = 1,
221 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
222 		.colorspace_default = V4L2_COLORSPACE_SRGB,
223 	},
224 	{
225 		.fourcc		    = V4L2_PIX_FMT_XBGR32,
226 		.align		    = 64,
227 		.bit_depth	    = 32,
228 		.plane_factor	    = { P3(1.0) },
229 		.num_planes	    = 1,
230 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
231 		.colorspace_default = V4L2_COLORSPACE_SRGB,
232 	},
233 	{
234 		.fourcc		    = V4L2_PIX_FMT_RGBX32,
235 		.align		    = 64,
236 		.bit_depth	    = 32,
237 		.plane_factor	    = { P3(1.0) },
238 		.num_planes	    = 1,
239 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
240 		.colorspace_default = V4L2_COLORSPACE_SRGB,
241 	},
242 	{
243 		.fourcc		    = V4L2_PIX_FMT_RGB48,
244 		.align		    = 64,
245 		.bit_depth	    = 48,
246 		.plane_factor	    = { P3(1.0) },
247 		.num_planes	    = 1,
248 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
249 		.colorspace_default = V4L2_COLORSPACE_SRGB,
250 	},
251 	{
252 		.fourcc		    = V4L2_PIX_FMT_BGR48,
253 		.align		    = 64,
254 		.bit_depth	    = 48,
255 		.plane_factor	    = { P3(1.0) },
256 		.num_planes	    = 1,
257 		.colorspace_mask    = V4L2_COLORSPACE_MASK_ALL_SRGB,
258 		.colorspace_default = V4L2_COLORSPACE_SRGB,
259 	},
260 	/* Bayer formats - 8-bit */
261 	{
262 		.fourcc		    = V4L2_PIX_FMT_SRGGB8,
263 		.bit_depth	    = 8,
264 		.align		    = 32,
265 		.plane_factor	    = { P3(1.0) },
266 		.num_planes	    = 1,
267 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
268 		.colorspace_default = V4L2_COLORSPACE_RAW,
269 	},
270 	{
271 		.fourcc		    = V4L2_PIX_FMT_SBGGR8,
272 		.bit_depth	    = 8,
273 		.align		    = 32,
274 		.plane_factor	    = { P3(1.0) },
275 		.num_planes	    = 1,
276 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
277 		.colorspace_default = V4L2_COLORSPACE_RAW,
278 	},
279 	{
280 		.fourcc		    = V4L2_PIX_FMT_SGRBG8,
281 		.bit_depth	    = 8,
282 		.align		    = 32,
283 		.plane_factor	    = { P3(1.0) },
284 		.num_planes	    = 1,
285 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
286 		.colorspace_default = V4L2_COLORSPACE_RAW,
287 	},
288 	{
289 		.fourcc		    = V4L2_PIX_FMT_SGBRG8,
290 		.bit_depth	    = 8,
291 		.align		    = 32,
292 		.plane_factor	    = { P3(1.0) },
293 		.num_planes	    = 1,
294 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
295 		.colorspace_default = V4L2_COLORSPACE_RAW,
296 	},
297 	/* Bayer formats - 16-bit */
298 	{
299 		.fourcc		    = V4L2_PIX_FMT_SRGGB16,
300 		.bit_depth	    = 16,
301 		.align		    = 32,
302 		.plane_factor	    = { P3(1.0) },
303 		.num_planes	    = 1,
304 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
305 		.colorspace_default = V4L2_COLORSPACE_RAW,
306 	},
307 	{
308 		.fourcc		    = V4L2_PIX_FMT_SBGGR16,
309 		.bit_depth	    = 16,
310 		.align		    = 32,
311 		.plane_factor	    = { P3(1.0) },
312 		.num_planes	    = 1,
313 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
314 		.colorspace_default = V4L2_COLORSPACE_RAW,
315 	},
316 	{
317 		.fourcc		    = V4L2_PIX_FMT_SGRBG16,
318 		.bit_depth	    = 16,
319 		.align		    = 32,
320 		.plane_factor	    = { P3(1.0) },
321 		.num_planes	    = 1,
322 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
323 		.colorspace_default = V4L2_COLORSPACE_RAW,
324 	},
325 	{
326 		.fourcc		    = V4L2_PIX_FMT_SGBRG16,
327 		.bit_depth	    = 16,
328 		.align		    = 32,
329 		.plane_factor	    = { P3(1.0) },
330 		.num_planes	    = 1,
331 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
332 		.colorspace_default = V4L2_COLORSPACE_RAW,
333 	},
334 	{
335 		/* Bayer formats unpacked to 16bpp */
336 		/* 10 bit */
337 		.fourcc		    = V4L2_PIX_FMT_SRGGB10,
338 		.bit_depth	    = 16,
339 		.align		    = 32,
340 		.plane_factor	    = { P3(1.0) },
341 		.num_planes	    = 1,
342 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
343 		.colorspace_default = V4L2_COLORSPACE_RAW,
344 	},
345 	{
346 		.fourcc		    = V4L2_PIX_FMT_SBGGR10,
347 		.bit_depth	    = 16,
348 		.align		    = 32,
349 		.plane_factor	    = { P3(1.0) },
350 		.num_planes	    = 1,
351 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
352 		.colorspace_default = V4L2_COLORSPACE_RAW,
353 	},
354 	{
355 		.fourcc		    = V4L2_PIX_FMT_SGRBG10,
356 		.bit_depth	    = 16,
357 		.align		    = 32,
358 		.plane_factor	    = { P3(1.0) },
359 		.num_planes	    = 1,
360 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
361 		.colorspace_default = V4L2_COLORSPACE_RAW,
362 	},
363 	{
364 		.fourcc		    = V4L2_PIX_FMT_SGBRG10,
365 		.bit_depth	    = 16,
366 		.align		    = 32,
367 		.plane_factor	    = { P3(1.0) },
368 		.num_planes	    = 1,
369 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
370 		.colorspace_default = V4L2_COLORSPACE_RAW,
371 	},
372 	{
373 		/* 12 bit */
374 		.fourcc		    = V4L2_PIX_FMT_SRGGB12,
375 		.bit_depth	    = 16,
376 		.align		    = 32,
377 		.plane_factor	    = { P3(1.0) },
378 		.num_planes	    = 1,
379 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
380 		.colorspace_default = V4L2_COLORSPACE_RAW,
381 	},
382 	{
383 		.fourcc		    = V4L2_PIX_FMT_SBGGR12,
384 		.bit_depth	    = 16,
385 		.align		    = 32,
386 		.plane_factor	    = { P3(1.0) },
387 		.num_planes	    = 1,
388 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
389 		.colorspace_default = V4L2_COLORSPACE_RAW,
390 	},
391 	{
392 		.fourcc		    = V4L2_PIX_FMT_SGRBG12,
393 		.bit_depth	    = 16,
394 		.align		    = 32,
395 		.plane_factor	    = { P3(1.0) },
396 		.num_planes	    = 1,
397 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
398 		.colorspace_default = V4L2_COLORSPACE_RAW,
399 	},
400 	{
401 		.fourcc		    = V4L2_PIX_FMT_SGBRG12,
402 		.bit_depth	    = 16,
403 		.align		    = 32,
404 		.plane_factor	    = { P3(1.0) },
405 		.num_planes	    = 1,
406 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
407 		.colorspace_default = V4L2_COLORSPACE_RAW,
408 	},
409 	{
410 		/* 14 bit */
411 		.fourcc		    = V4L2_PIX_FMT_SRGGB14,
412 		.bit_depth	    = 16,
413 		.align		    = 32,
414 		.plane_factor	    = { P3(1.0) },
415 		.num_planes	    = 1,
416 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
417 		.colorspace_default = V4L2_COLORSPACE_RAW,
418 	},
419 	{
420 		.fourcc		    = V4L2_PIX_FMT_SBGGR14,
421 		.bit_depth	    = 16,
422 		.align		    = 32,
423 		.plane_factor	    = { P3(1.0) },
424 		.num_planes	    = 1,
425 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
426 		.colorspace_default = V4L2_COLORSPACE_RAW,
427 	},
428 	{
429 		.fourcc		    = V4L2_PIX_FMT_SGRBG14,
430 		.bit_depth	    = 16,
431 		.align		    = 32,
432 		.plane_factor	    = { P3(1.0) },
433 		.num_planes	    = 1,
434 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
435 		.colorspace_default = V4L2_COLORSPACE_RAW,
436 	},
437 	{
438 		.fourcc		    = V4L2_PIX_FMT_SGBRG14,
439 		.bit_depth	    = 16,
440 		.align		    = 32,
441 		.plane_factor	    = { P3(1.0) },
442 		.num_planes	    = 1,
443 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
444 		.colorspace_default = V4L2_COLORSPACE_RAW,
445 	},
446 	/* Bayer formats - 16-bit PiSP Compressed */
447 	{
448 		.fourcc		    = V4L2_PIX_FMT_PISP_COMP1_BGGR,
449 		.bit_depth	    = 8,
450 		.align		    = 32,
451 		.plane_factor	    = { P3(1.0) },
452 		.num_planes	    = 1,
453 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
454 		.colorspace_default = V4L2_COLORSPACE_RAW,
455 	},
456 	{
457 		.fourcc		    = V4L2_PIX_FMT_PISP_COMP1_RGGB,
458 		.bit_depth	    = 8,
459 		.align		    = 32,
460 		.plane_factor	    = { P3(1.0) },
461 		.num_planes	    = 1,
462 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
463 		.colorspace_default = V4L2_COLORSPACE_RAW,
464 	},
465 	{
466 		.fourcc		    = V4L2_PIX_FMT_PISP_COMP1_GRBG,
467 		.bit_depth	    = 8,
468 		.align		    = 32,
469 		.plane_factor	    = { P3(1.0) },
470 		.num_planes	    = 1,
471 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
472 		.colorspace_default = V4L2_COLORSPACE_RAW,
473 	},
474 	{
475 		.fourcc		    = V4L2_PIX_FMT_PISP_COMP1_GBRG,
476 		.bit_depth	    = 8,
477 		.align		    = 32,
478 		.plane_factor	    = { P3(1.0) },
479 		.num_planes	    = 1,
480 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
481 		.colorspace_default = V4L2_COLORSPACE_RAW,
482 	},
483 	/* Greyscale Formats */
484 	{
485 		.fourcc		= V4L2_PIX_FMT_GREY,
486 		.bit_depth	= 8,
487 		.align		= 32,
488 		.num_planes	= 1,
489 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
490 		.colorspace_default = V4L2_COLORSPACE_RAW,
491 	},
492 	{
493 		.fourcc		= V4L2_PIX_FMT_Y16,
494 		.bit_depth	= 16,
495 		.align		= 32,
496 		.plane_factor	= { P3(1.0) },
497 		.num_planes	= 1,
498 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
499 		.colorspace_default = V4L2_COLORSPACE_RAW,
500 	},
501 	{
502 		.fourcc		= V4L2_PIX_FMT_PISP_COMP1_MONO,
503 		.bit_depth	= 8,
504 		.align		= 32,
505 		.plane_factor	= { P3(1.0) },
506 		.num_planes	= 1,
507 		.colorspace_mask    = V4L2_COLORSPACE_MASK_RAW,
508 		.colorspace_default = V4L2_COLORSPACE_RAW,
509 	},
510 };
511 
512 static const struct pisp_be_format meta_out_supported_formats[] = {
513 	/* Configuration buffer format. */
514 	{
515 		.fourcc		    = V4L2_META_FMT_RPI_BE_CFG,
516 	},
517 };
518 
519 #endif /* _PISP_BE_FORMATS_ */
520