42c3b6f42b5c6216537801e128cc992b65a8bc25
[openwrt/staging/ldir.git] /
1 From 2e0e1d7b493dffe7baa763d499e51ba42f0bad19 Mon Sep 17 00:00:00 2001
2 From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
3 Date: Fri, 29 Sep 2023 17:14:11 +0300
4 Subject: [PATCH] media: rp1: cfe: Add cfe_find_16bit_code() and
5 cfe_find_compressed_code()
6
7 Add helper functions which, given an mbus code, return the 16-bit
8 remapped mbus code or the compressed mbus code.
9
10 Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
11 ---
12 .../media/platform/raspberrypi/rp1_cfe/cfe.c | 40 +++++++++++++++++++
13 .../media/platform/raspberrypi/rp1_cfe/cfe.h | 2 +
14 2 files changed, 42 insertions(+)
15
16 --- a/drivers/media/platform/raspberrypi/rp1_cfe/cfe.c
17 +++ b/drivers/media/platform/raspberrypi/rp1_cfe/cfe.c
18 @@ -473,6 +473,46 @@ const struct cfe_fmt *find_format_by_pix
19 return NULL;
20 }
21
22 +/*
23 + * Given the mbus code, find the 16 bit remapped code. Returns 0 if no remap
24 + * possible.
25 + */
26 +u32 cfe_find_16bit_code(u32 code)
27 +{
28 + const struct cfe_fmt *cfe_fmt;
29 +
30 + cfe_fmt = find_format_by_code(code);
31 +
32 + if (!cfe_fmt || !cfe_fmt->remap[CFE_REMAP_16BIT])
33 + return 0;
34 +
35 + cfe_fmt = find_format_by_pix(cfe_fmt->remap[CFE_REMAP_16BIT]);
36 + if (!cfe_fmt)
37 + return 0;
38 +
39 + return cfe_fmt->code;
40 +}
41 +
42 +/*
43 + * Given the mbus code, find the 8 bit compressed code. Returns 0 if no remap
44 + * possible.
45 + */
46 +u32 cfe_find_compressed_code(u32 code)
47 +{
48 + const struct cfe_fmt *cfe_fmt;
49 +
50 + cfe_fmt = find_format_by_code(code);
51 +
52 + if (!cfe_fmt || !cfe_fmt->remap[CFE_REMAP_COMPRESSED])
53 + return 0;
54 +
55 + cfe_fmt = find_format_by_pix(cfe_fmt->remap[CFE_REMAP_COMPRESSED]);
56 + if (!cfe_fmt)
57 + return 0;
58 +
59 + return cfe_fmt->code;
60 +}
61 +
62 static int cfe_calc_format_size_bpl(struct cfe_device *cfe,
63 const struct cfe_fmt *fmt,
64 struct v4l2_format *f)
65 --- a/drivers/media/platform/raspberrypi/rp1_cfe/cfe.h
66 +++ b/drivers/media/platform/raspberrypi/rp1_cfe/cfe.h
67 @@ -37,5 +37,7 @@ extern const struct v4l2_mbus_framefmt c
68
69 const struct cfe_fmt *find_format_by_code(u32 code);
70 const struct cfe_fmt *find_format_by_pix(u32 pixelformat);
71 +u32 cfe_find_16bit_code(u32 code);
72 +u32 cfe_find_compressed_code(u32 code);
73
74 #endif