Re: [PATCH v3, 12/15] drm/mediatek: separate ccorr module

2021-01-12 Thread Chun-Kuang Hu
Hi, Yongqiang:

Yongqiang Niu  於 2021年1月11日 週一 下午3:54寫道:
>
> ccorr ctm matrix bits will be different in mt8192

This patch has conflicts with the series "Decouple Mediatek DRM sub
driver" [1] which has been applied to mediatek-drm-next, so please
rebase this patch onto mediatek-drm-next.

[1] https://patchwork.kernel.org/project/linux-mediatek/list/?series=399915

Regards,
Chun-Kuang.

>
> Signed-off-by: Yongqiang Niu 
> ---
>  drivers/gpu/drm/mediatek/Makefile   |   3 +-
>  drivers/gpu/drm/mediatek/mtk_disp_ccorr.c   | 222 
> 
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c |  92 +---
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c  |   8 +-
>  drivers/gpu/drm/mediatek/mtk_drm_drv.h  |   1 +
>  5 files changed, 231 insertions(+), 95 deletions(-)
>  create mode 100644 drivers/gpu/drm/mediatek/mtk_disp_ccorr.c
>
> diff --git a/drivers/gpu/drm/mediatek/Makefile 
> b/drivers/gpu/drm/mediatek/Makefile
> index ce5ad59..a02f534 100644
> --- a/drivers/gpu/drm/mediatek/Makefile
> +++ b/drivers/gpu/drm/mediatek/Makefile
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0
>
> -mediatek-drm-y := mtk_disp_color.o \
> +mediatek-drm-y := mtk_disp_ccorr.o \
> + mtk_disp_color.o \
>   mtk_disp_gamma.o \
>   mtk_disp_ovl.o \
>   mtk_disp_postmask.o \
> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ccorr.c 
> b/drivers/gpu/drm/mediatek/mtk_disp_ccorr.c
> new file mode 100644
> index 000..63b3ef6
> --- /dev/null
> +++ b/drivers/gpu/drm/mediatek/mtk_disp_ccorr.c
> @@ -0,0 +1,222 @@
> +/*
> + * SPDX-License-Identifier:
> + *
> + * Copyright (c) 2020 MediaTek Inc.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "mtk_drm_crtc.h"
> +#include "mtk_drm_ddp_comp.h"
> +
> +#define DISP_CCORR_EN  0x
> +#define CCORR_EN   BIT(0)
> +#define DISP_CCORR_CFG 0x0020
> +#define CCORR_RELAY_MODE   BIT(0)
> +#define CCORR_ENGINE_ENBIT(1)
> +#define CCORR_GAMMA_OFFBIT(2)
> +#define CCORR_WGAMUT_SRC_CLIP  BIT(3)
> +#define DISP_CCORR_SIZE0x0030
> +#define DISP_CCORR_COEF_0  0x0080
> +#define DISP_CCORR_COEF_1  0x0084
> +#define DISP_CCORR_COEF_2  0x0088
> +#define DISP_CCORR_COEF_3  0x008C
> +#define DISP_CCORR_COEF_4  0x0090
> +
> +struct mtk_disp_ccorr_data {
> +   u32 reserved;
> +};
> +
> +/**
> + * struct mtk_disp_ccorr - DISP_CCORR driver structure
> + * @ddp_comp - structure containing type enum and hardware resources
> + * @crtc - associated crtc to report irq events to
> + */
> +struct mtk_disp_ccorr {
> +   struct mtk_ddp_comp ddp_comp;
> +   const struct mtk_disp_ccorr_data*data;
> +};
> +
> +static inline struct mtk_disp_ccorr *comp_to_ccorr(struct mtk_ddp_comp *comp)
> +{
> +   return container_of(comp, struct mtk_disp_ccorr, ddp_comp);
> +}
> +
> +static void mtk_ccorr_config(struct mtk_ddp_comp *comp, unsigned int w,
> +unsigned int h, unsigned int vrefresh,
> +unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
> +{
> +   mtk_ddp_write(cmdq_pkt, w << 16 | h, comp, DISP_CCORR_SIZE);
> +   mtk_ddp_write(cmdq_pkt, CCORR_ENGINE_EN, comp, DISP_CCORR_CFG);
> +}
> +
> +static void mtk_ccorr_start(struct mtk_ddp_comp *comp)
> +{
> +   writel(CCORR_EN, comp->regs + DISP_CCORR_EN);
> +}
> +
> +static void mtk_ccorr_stop(struct mtk_ddp_comp *comp)
> +{
> +   writel_relaxed(0x0, comp->regs + DISP_CCORR_EN);
> +}
> +
> +/* Converts a DRM S31.32 value to the HW S1.10 format. */
> +static u16 mtk_ctm_s31_32_to_s1_10(u64 in)
> +{
> +   u16 r;
> +
> +   /* Sign bit. */
> +   r = in & BIT_ULL(63) ? BIT(11) : 0;
> +
> +   if ((in & GENMASK_ULL(62, 33)) > 0) {
> +   /* identity value 0x1 -> 0x400, */
> +   /* if bigger this, set it to max 0x7ff. */
> +   r |= GENMASK(10, 0);
> +   } else {
> +   /* take the 11 most important bits. */
> +   r |= (in >> 22) & GENMASK(10, 0);
> +   }
> +
> +   return r;
> +}
> +
> +static void mtk_ccorr_ctm_set(struct mtk_ddp_comp *comp,
> + struct drm_crtc_state *state)
> +{
> +   struct drm_property_blob *blob = state->ctm;
> +   struct drm_color_ctm *ctm;
> +   const u64 *input;
> +   uint16_t coeffs[9] = { 0 };
> +   int i;
> +   struct cmdq_pkt *cmdq_pkt = NULL;
> +
> +   if (!blob)
> +   return;
> +
> +   ctm = (struct drm_color_ctm *)blob->data;
> +   input = ctm->matrix;
> +
> +   for (i 

[PATCH v3, 12/15] drm/mediatek: separate ccorr module

2021-01-10 Thread Yongqiang Niu
ccorr ctm matrix bits will be different in mt8192

Signed-off-by: Yongqiang Niu 
---
 drivers/gpu/drm/mediatek/Makefile   |   3 +-
 drivers/gpu/drm/mediatek/mtk_disp_ccorr.c   | 222 
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c |  92 +---
 drivers/gpu/drm/mediatek/mtk_drm_drv.c  |   8 +-
 drivers/gpu/drm/mediatek/mtk_drm_drv.h  |   1 +
 5 files changed, 231 insertions(+), 95 deletions(-)
 create mode 100644 drivers/gpu/drm/mediatek/mtk_disp_ccorr.c

diff --git a/drivers/gpu/drm/mediatek/Makefile 
b/drivers/gpu/drm/mediatek/Makefile
index ce5ad59..a02f534 100644
--- a/drivers/gpu/drm/mediatek/Makefile
+++ b/drivers/gpu/drm/mediatek/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
-mediatek-drm-y := mtk_disp_color.o \
+mediatek-drm-y := mtk_disp_ccorr.o \
+ mtk_disp_color.o \
  mtk_disp_gamma.o \
  mtk_disp_ovl.o \
  mtk_disp_postmask.o \
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ccorr.c 
b/drivers/gpu/drm/mediatek/mtk_disp_ccorr.c
new file mode 100644
index 000..63b3ef6
--- /dev/null
+++ b/drivers/gpu/drm/mediatek/mtk_disp_ccorr.c
@@ -0,0 +1,222 @@
+/*
+ * SPDX-License-Identifier:
+ *
+ * Copyright (c) 2020 MediaTek Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mtk_drm_crtc.h"
+#include "mtk_drm_ddp_comp.h"
+
+#define DISP_CCORR_EN  0x
+#define CCORR_EN   BIT(0)
+#define DISP_CCORR_CFG 0x0020
+#define CCORR_RELAY_MODE   BIT(0)
+#define CCORR_ENGINE_ENBIT(1)
+#define CCORR_GAMMA_OFFBIT(2)
+#define CCORR_WGAMUT_SRC_CLIP  BIT(3)
+#define DISP_CCORR_SIZE0x0030
+#define DISP_CCORR_COEF_0  0x0080
+#define DISP_CCORR_COEF_1  0x0084
+#define DISP_CCORR_COEF_2  0x0088
+#define DISP_CCORR_COEF_3  0x008C
+#define DISP_CCORR_COEF_4  0x0090
+
+struct mtk_disp_ccorr_data {
+   u32 reserved;
+};
+
+/**
+ * struct mtk_disp_ccorr - DISP_CCORR driver structure
+ * @ddp_comp - structure containing type enum and hardware resources
+ * @crtc - associated crtc to report irq events to
+ */
+struct mtk_disp_ccorr {
+   struct mtk_ddp_comp ddp_comp;
+   const struct mtk_disp_ccorr_data*data;
+};
+
+static inline struct mtk_disp_ccorr *comp_to_ccorr(struct mtk_ddp_comp *comp)
+{
+   return container_of(comp, struct mtk_disp_ccorr, ddp_comp);
+}
+
+static void mtk_ccorr_config(struct mtk_ddp_comp *comp, unsigned int w,
+unsigned int h, unsigned int vrefresh,
+unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
+{
+   mtk_ddp_write(cmdq_pkt, w << 16 | h, comp, DISP_CCORR_SIZE);
+   mtk_ddp_write(cmdq_pkt, CCORR_ENGINE_EN, comp, DISP_CCORR_CFG);
+}
+
+static void mtk_ccorr_start(struct mtk_ddp_comp *comp)
+{
+   writel(CCORR_EN, comp->regs + DISP_CCORR_EN);
+}
+
+static void mtk_ccorr_stop(struct mtk_ddp_comp *comp)
+{
+   writel_relaxed(0x0, comp->regs + DISP_CCORR_EN);
+}
+
+/* Converts a DRM S31.32 value to the HW S1.10 format. */
+static u16 mtk_ctm_s31_32_to_s1_10(u64 in)
+{
+   u16 r;
+
+   /* Sign bit. */
+   r = in & BIT_ULL(63) ? BIT(11) : 0;
+
+   if ((in & GENMASK_ULL(62, 33)) > 0) {
+   /* identity value 0x1 -> 0x400, */
+   /* if bigger this, set it to max 0x7ff. */
+   r |= GENMASK(10, 0);
+   } else {
+   /* take the 11 most important bits. */
+   r |= (in >> 22) & GENMASK(10, 0);
+   }
+
+   return r;
+}
+
+static void mtk_ccorr_ctm_set(struct mtk_ddp_comp *comp,
+ struct drm_crtc_state *state)
+{
+   struct drm_property_blob *blob = state->ctm;
+   struct drm_color_ctm *ctm;
+   const u64 *input;
+   uint16_t coeffs[9] = { 0 };
+   int i;
+   struct cmdq_pkt *cmdq_pkt = NULL;
+
+   if (!blob)
+   return;
+
+   ctm = (struct drm_color_ctm *)blob->data;
+   input = ctm->matrix;
+
+   for (i = 0; i < ARRAY_SIZE(coeffs); i++)
+   coeffs[i] = mtk_ctm_s31_32_to_s1_10(input[i]);
+
+   mtk_ddp_write(cmdq_pkt, coeffs[0] << 16 | coeffs[1],
+ comp, DISP_CCORR_COEF_0);
+   mtk_ddp_write(cmdq_pkt, coeffs[2] << 16 | coeffs[3],
+ comp, DISP_CCORR_COEF_1);
+   mtk_ddp_write(cmdq_pkt, coeffs[4] << 16 | coeffs[5],
+ comp, DISP_CCORR_COEF_2);
+   mtk_ddp_write(cmdq_pkt, coeffs[6] << 16 | coeffs[7],
+ comp, DISP_CCORR_COEF_3);
+   mtk_ddp_write(cmdq_pkt, coeffs[8] << 16,
+ comp,