From: Paul Kocialkowski <paul.kocialkow...@bootlin.com>

[ Upstream commit ded874ece29d3fe2abd3775810a06056067eb68c ]

This introduces two macros: RGA_COLOR_FMT_IS_YUV and RGA_COLOR_FMT_IS_RGB
which allow quick checking of the colorspace familily of a RGA color format.

These macros are then used to refactor the logic for CSC mode selection.
The two nested tests for input colorspace are simplified into a single one,
with a logical and, making the whole more readable.

Signed-off-by: Paul Kocialkowski <paul.kocialkow...@bootlin.com>
Reviewed-by: Ezequiel Garcia <ezequ...@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-ci...@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+hua...@kernel.org>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 drivers/media/platform/rockchip/rga/rga-hw.c | 23 +++++++++-----------
 drivers/media/platform/rockchip/rga/rga-hw.h |  5 +++++
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/media/platform/rockchip/rga/rga-hw.c 
b/drivers/media/platform/rockchip/rga/rga-hw.c
index 96d1b1b3fe8e8..6d12491b79d78 100644
--- a/drivers/media/platform/rockchip/rga/rga-hw.c
+++ b/drivers/media/platform/rockchip/rga/rga-hw.c
@@ -208,22 +208,19 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx)
        dst_info.data.format = ctx->out.fmt->hw_format;
        dst_info.data.swap = ctx->out.fmt->color_swap;
 
-       if (ctx->in.fmt->hw_format >= RGA_COLOR_FMT_YUV422SP) {
-               if (ctx->out.fmt->hw_format < RGA_COLOR_FMT_YUV422SP) {
-                       switch (ctx->in.colorspace) {
-                       case V4L2_COLORSPACE_REC709:
-                               src_info.data.csc_mode =
-                                       RGA_SRC_CSC_MODE_BT709_R0;
-                               break;
-                       default:
-                               src_info.data.csc_mode =
-                                       RGA_SRC_CSC_MODE_BT601_R0;
-                               break;
-                       }
+       if (RGA_COLOR_FMT_IS_YUV(ctx->in.fmt->hw_format) &&
+           RGA_COLOR_FMT_IS_RGB(ctx->out.fmt->hw_format)) {
+               switch (ctx->in.colorspace) {
+               case V4L2_COLORSPACE_REC709:
+                       src_info.data.csc_mode = RGA_SRC_CSC_MODE_BT709_R0;
+                       break;
+               default:
+                       src_info.data.csc_mode = RGA_SRC_CSC_MODE_BT601_R0;
+                       break;
                }
        }
 
-       if (ctx->out.fmt->hw_format >= RGA_COLOR_FMT_YUV422SP) {
+       if (RGA_COLOR_FMT_IS_YUV(ctx->out.fmt->hw_format)) {
                switch (ctx->out.colorspace) {
                case V4L2_COLORSPACE_REC709:
                        dst_info.data.csc_mode = RGA_SRC_CSC_MODE_BT709_R0;
diff --git a/drivers/media/platform/rockchip/rga/rga-hw.h 
b/drivers/media/platform/rockchip/rga/rga-hw.h
index ca3c204abe420..3e4b70eb9ced5 100644
--- a/drivers/media/platform/rockchip/rga/rga-hw.h
+++ b/drivers/media/platform/rockchip/rga/rga-hw.h
@@ -103,6 +103,11 @@
 #define RGA_COLOR_FMT_CP_8BPP 15
 #define RGA_COLOR_FMT_MASK 15
 
+#define RGA_COLOR_FMT_IS_YUV(fmt) \
+       (((fmt) >= RGA_COLOR_FMT_YUV422SP) && ((fmt) < RGA_COLOR_FMT_CP_1BPP))
+#define RGA_COLOR_FMT_IS_RGB(fmt) \
+       ((fmt) < RGA_COLOR_FMT_YUV422SP)
+
 #define RGA_COLOR_NONE_SWAP 0
 #define RGA_COLOR_RB_SWAP 1
 #define RGA_COLOR_ALPHA_SWAP 2
-- 
2.25.1



Reply via email to