From ef817a8f5bfd38d91f9250b138a90edafb7b21a0 Mon Sep 17 00:00:00 2001
From: Jernej Skrabec <jernej.skrabec@gmail.com>
Date: Sat, 7 Oct 2023 09:45:25 +0200
Subject: [PATCH 16/23] media: cedrus: add format filtering based on depth and
 src format

Some Cedrus variant, like that found in H6, support special output
formats only with specific codecs, like H265.

Add extra filtering fields based on bit depth and source format.

Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
---
 drivers/staging/media/sunxi/cedrus/cedrus_video.c | 7 +++++++
 drivers/staging/media/sunxi/cedrus/cedrus_video.h | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index b00feaf4072c..75b6f2e85a5f 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -87,6 +87,13 @@ static struct cedrus_format *cedrus_find_format(struct cedrus_ctx *ctx,
 		    !(fmt->directions & directions))
 			continue;
 
+		if (fmt->depth && fmt->depth != ctx->bit_depth)
+			continue;
+
+		if (fmt->src_format &&
+		    fmt->src_format != ctx->src_fmt.pixelformat)
+			continue;
+
 		if (fmt->pixelformat == pixelformat)
 			break;
 
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.h b/drivers/staging/media/sunxi/cedrus/cedrus_video.h
index 8e1afc16a6a1..c8e9909ecdee 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.h
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.h
@@ -20,6 +20,8 @@ struct cedrus_format {
 	u32		pixelformat;
 	u32		directions;
 	unsigned int	capabilities;
+	unsigned int	depth;
+	u32		src_format;
 };
 
 extern const struct v4l2_ioctl_ops cedrus_ioctl_ops;
-- 
2.42.0

