drm/komeda: Enable color-encoding (YUV format) support
authorLowry Li (Arm Technology China) <Lowry.Li@arm.com>
Thu, 16 May 2019 06:13:13 +0000 (07:13 +0100)
committerLiviu Dudau <Liviu.Dudau@arm.com>
Wed, 19 Jun 2019 10:42:17 +0000 (11:42 +0100)
Adds color-encoding properties if layer can support YUV format.
Updates HW YUV-RGB matrix state according to the color-encoding
properties.

Signed-off-by: Lowry Li (Arm Technology China) <lowry.li@arm.com>
Reviewed-by: James Qian Wang (Arm Technology China) <james.qian.wang@arm.com>
Signed-off-by: Liviu Dudau <liviu.dudau@arm.com>
drivers/gpu/drm/arm/display/komeda/Makefile
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c [new file with mode: 0644]
drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h [new file with mode: 0644]
drivers/gpu/drm/arm/display/komeda/komeda_plane.c

index 16a1ea443de260875bdf790275e0d92fc5c1aee7..5c3900c2e764feac9a6ea5d932a0af2f0821c00d 100644 (file)
@@ -8,6 +8,7 @@ komeda-y := \
        komeda_drv.o \
        komeda_dev.o \
        komeda_format_caps.o \
+       komeda_color_mgmt.o \
        komeda_pipeline.o \
        komeda_pipeline_state.o \
        komeda_framebuffer.o \
index d467944f51a54af8ea51fe6083ab2dcd024b306b..79ff71b50032b52aa9adef21bbf54ec0a88b988d 100644 (file)
@@ -10,6 +10,7 @@
 #include "komeda_kms.h"
 #include "malidp_io.h"
 #include "komeda_framebuffer.h"
+#include "komeda_color_mgmt.h"
 
 static void get_resources_id(u32 hw_id, u32 *pipe_id, u32 *comp_id)
 {
@@ -239,6 +240,11 @@ static void d71_layer_update(struct komeda_component *c,
                }
 
                malidp_write32(reg, LAYER_R_CONTROL, upsampling);
+               malidp_write_group(reg, LAYER_YUV_RGB_COEFF0,
+                                  KOMEDA_N_YUV2RGB_COEFFS,
+                                  komeda_select_yuv2rgb_coeffs(
+                                       plane_st->color_encoding,
+                                       plane_st->color_range));
        }
 
        malidp_write32(reg, LAYER_FMT, kfb->format_caps->hw_id);
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c
new file mode 100644 (file)
index 0000000..9d14a92
--- /dev/null
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) COPYRIGHT 2019 ARM Limited. All rights reserved.
+ * Author: James.Qian.Wang <james.qian.wang@arm.com>
+ *
+ */
+
+#include "komeda_color_mgmt.h"
+
+/* 10bit precision YUV2RGB matrix */
+static const s32 yuv2rgb_bt601_narrow[KOMEDA_N_YUV2RGB_COEFFS] = {
+       1192,    0, 1634,
+       1192, -401, -832,
+       1192, 2066,    0,
+         64,  512,  512
+};
+
+static const s32 yuv2rgb_bt601_wide[KOMEDA_N_YUV2RGB_COEFFS] = {
+       1024,    0, 1436,
+       1024, -352, -731,
+       1024, 1815,    0,
+          0,  512,  512
+};
+
+static const s32 yuv2rgb_bt709_narrow[KOMEDA_N_YUV2RGB_COEFFS] = {
+       1192,    0, 1836,
+       1192, -218, -546,
+       1192, 2163,    0,
+         64,  512,  512
+};
+
+static const s32 yuv2rgb_bt709_wide[KOMEDA_N_YUV2RGB_COEFFS] = {
+       1024,    0, 1613,
+       1024, -192, -479,
+       1024, 1900,    0,
+          0,  512,  512
+};
+
+static const s32 yuv2rgb_bt2020[KOMEDA_N_YUV2RGB_COEFFS] = {
+       1024,    0, 1476,
+       1024, -165, -572,
+       1024, 1884,    0,
+          0,  512,  512
+};
+
+const s32 *komeda_select_yuv2rgb_coeffs(u32 color_encoding, u32 color_range)
+{
+       bool narrow = color_range == DRM_COLOR_YCBCR_LIMITED_RANGE;
+       const s32 *coeffs;
+
+       switch (color_encoding) {
+       case DRM_COLOR_YCBCR_BT709:
+               coeffs = narrow ? yuv2rgb_bt709_narrow : yuv2rgb_bt709_wide;
+               break;
+       case DRM_COLOR_YCBCR_BT601:
+               coeffs = narrow ? yuv2rgb_bt601_narrow : yuv2rgb_bt601_wide;
+               break;
+       case DRM_COLOR_YCBCR_BT2020:
+               coeffs = yuv2rgb_bt2020;
+               break;
+       default:
+               coeffs = NULL;
+               break;
+       }
+
+       return coeffs;
+}
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h
new file mode 100644 (file)
index 0000000..a2df218
--- /dev/null
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * (C) COPYRIGHT 2019 ARM Limited. All rights reserved.
+ * Author: James.Qian.Wang <james.qian.wang@arm.com>
+ *
+ */
+
+#ifndef _KOMEDA_COLOR_MGMT_H_
+#define _KOMEDA_COLOR_MGMT_H_
+
+#include <drm/drm_color_mgmt.h>
+
+#define KOMEDA_N_YUV2RGB_COEFFS                12
+
+const s32 *komeda_select_yuv2rgb_coeffs(u32 color_encoding, u32 color_range);
+
+#endif
index 9009f87b7323de2e5dec1e01b4c075cda2271bc6..9e049ee9014aac414bcff4147822dd79f8025d3f 100644 (file)
@@ -137,6 +137,8 @@ static void komeda_plane_reset(struct drm_plane *plane)
                state->base.pixel_blend_mode = DRM_MODE_BLEND_PREMULTI;
                state->base.alpha = DRM_BLEND_ALPHA_OPAQUE;
                state->base.zpos = kplane->layer->base.id;
+               state->base.color_encoding = DRM_COLOR_YCBCR_BT601;
+               state->base.color_range = DRM_COLOR_YCBCR_LIMITED_RANGE;
                plane->state = &state->base;
                plane->state->plane = plane;
        }
@@ -332,6 +334,17 @@ static int komeda_plane_add(struct komeda_kms_dev *kms,
        if (err)
                goto cleanup;
 
+       err = drm_plane_create_color_properties(plane,
+                       BIT(DRM_COLOR_YCBCR_BT601) |
+                       BIT(DRM_COLOR_YCBCR_BT709) |
+                       BIT(DRM_COLOR_YCBCR_BT2020),
+                       BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
+                       BIT(DRM_COLOR_YCBCR_FULL_RANGE),
+                       DRM_COLOR_YCBCR_BT601,
+                       DRM_COLOR_YCBCR_LIMITED_RANGE);
+       if (err)
+               goto cleanup;
+
        return 0;
 cleanup:
        komeda_plane_destroy(plane);