From 2284027522b9840b8b85c09c55d2a42159886303 Mon Sep 17 00:00:00 2001
From: "Guoniu.zhou" <guoniu.zhou@nxp.com>
Date: Wed, 10 Aug 2022 17:02:26 +0800
Subject: [PATCH] LF-6806: dma: pxp: workaround for PXP when do RGB to gray
 color conversion

CSC2 engine in PXP has IC bug(TKT272216) and fixed after 7D PXP version.
Driver update new CSC coefficient provided by PXP IP owner(MLK-25625-02).
But when run e-ink case, it can't do clear operation after applying the
patch. We don't know reason until now, so add a temporary patch to fix it
and will remove after finding the root cause.

Signed-off-by: Guoniu.zhou <guoniu.zhou@nxp.com>
Reviewed-by: Robby Cai <robby.cai@nxp.com>
---
 drivers/dma/pxp/pxp_dma_v3.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/pxp/pxp_dma_v3.c b/drivers/dma/pxp/pxp_dma_v3.c
index 3d8e9f50ee13d..32e1da3953e2b 100644
--- a/drivers/dma/pxp/pxp_dma_v3.c
+++ b/drivers/dma/pxp/pxp_dma_v3.c
@@ -2762,15 +2762,30 @@ static int pxp_rotation0_config(struct pxp_pixmap *input)
 
 static int pxp_csc2_config(struct pxp_pixmap *output)
 {
-	if (is_yuv(output->format)) {
-		/* RGB -> YCbCr */
+	u32 coeffs[2][6] = {
+		{ 0x00810042, 0x07DA0019, 0x007007B6,
+		  0x07A20070, 0x001007EE, 0x00800080 },
+		{ 0x0096004D, 0x05DA001D, 0x007005B6,
+		  0x057C009E, 0x000005E6, 0x00000000 },
+	};
+	u32 legacy_mode = 0;
+
+	if (output->format == PXP_PIX_FMT_GREY ||
+	    output->format == PXP_PIX_FMT_GY04) {
+		pxp_writel(0x4, HW_PXP_CSC2_CTRL);
+		legacy_mode = 1;
+	} else if (is_yuv(output->format)) {
 		pxp_writel(0x6, HW_PXP_CSC2_CTRL);
-		pxp_writel(0x00810042, HW_PXP_CSC2_COEF0);
-		pxp_writel(0x07DA0019, HW_PXP_CSC2_COEF1);
-		pxp_writel(0x007007B6, HW_PXP_CSC2_COEF2);
-		pxp_writel(0x07A20070, HW_PXP_CSC2_COEF3);
-		pxp_writel(0x001007EE, HW_PXP_CSC2_COEF4);
-		pxp_writel(0x00800080, HW_PXP_CSC2_COEF5);
+		legacy_mode = 0;
+	}
+
+	if (is_yuv(output->format)) {
+		pxp_writel(coeffs[legacy_mode][0], HW_PXP_CSC2_COEF0);
+		pxp_writel(coeffs[legacy_mode][1], HW_PXP_CSC2_COEF1);
+		pxp_writel(coeffs[legacy_mode][2], HW_PXP_CSC2_COEF2);
+		pxp_writel(coeffs[legacy_mode][3], HW_PXP_CSC2_COEF3);
+		pxp_writel(coeffs[legacy_mode][4], HW_PXP_CSC2_COEF4);
+		pxp_writel(coeffs[legacy_mode][5], HW_PXP_CSC2_COEF5);
 	}
 
 	pxp_writel(BF_PXP_CTRL_ENABLE_CSC2(1), HW_PXP_CTRL_SET);
-- 
GitLab