diff mbox series

[v1,2/2] drm/komeda: Enable color-encoding (YUV format) support

Message ID 1557987170-24032-3-git-send-email-lowry.li@arm.com (mailing list archive)
State New, archived
Headers show
Series drm/komeda: Enable color-encoding (YUV format) support | expand

Commit Message

Lowry Li (Arm Technology China) May 16, 2019, 6:13 a.m. UTC
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>
---
 drivers/gpu/drm/arm/display/komeda/Makefile        |  1 +
 .../gpu/drm/arm/display/komeda/d71/d71_component.c |  6 ++
 .../gpu/drm/arm/display/komeda/komeda_color_mgmt.c | 67 ++++++++++++++++++++++
 .../gpu/drm/arm/display/komeda/komeda_color_mgmt.h | 17 ++++++
 drivers/gpu/drm/arm/display/komeda/komeda_plane.c  | 13 +++++
 5 files changed, 104 insertions(+)
 create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c
 create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h

Comments

James Qian Wang May 20, 2019, 5:50 a.m. UTC | #1
On Thu, May 16, 2019 at 02:13:13PM +0800, Lowry Li (Arm Technology China) wrote:
> 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>
> ---
>  drivers/gpu/drm/arm/display/komeda/Makefile        |  1 +
>  .../gpu/drm/arm/display/komeda/d71/d71_component.c |  6 ++
>  .../gpu/drm/arm/display/komeda/komeda_color_mgmt.c | 67 ++++++++++++++++++++++
>  .../gpu/drm/arm/display/komeda/komeda_color_mgmt.h | 17 ++++++
>  drivers/gpu/drm/arm/display/komeda/komeda_plane.c  | 13 +++++
>  5 files changed, 104 insertions(+)
>  create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c
>  create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h
> 
> diff --git a/drivers/gpu/drm/arm/display/komeda/Makefile b/drivers/gpu/drm/arm/display/komeda/Makefile
> index d7e29fc..73b8e8b 100644
> --- a/drivers/gpu/drm/arm/display/komeda/Makefile
> +++ b/drivers/gpu/drm/arm/display/komeda/Makefile
> @@ -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 \
> diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> index dfc70f5..b85514b 100644
> --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> @@ -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
> index 0000000..9d14a92
> --- /dev/null
> +++ b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c
> @@ -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
> index 0000000..a2df218
> --- /dev/null
> +++ b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h
> @@ -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
> diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_plane.c b/drivers/gpu/drm/arm/display/komeda/komeda_plane.c
> index f344048..bcf30a7 100644
> --- a/drivers/gpu/drm/arm/display/komeda/komeda_plane.c
> +++ b/drivers/gpu/drm/arm/display/komeda/komeda_plane.c
> @@ -135,6 +135,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;
>  	}
> @@ -330,6 +332,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);
> -- 
> 1.9.1
> 
 
Reviewed-by: James Qian Wang (Arm Technology China) <james.qian.wang@arm.com>

Looks good to me

Thank you
diff mbox series

Patch

diff --git a/drivers/gpu/drm/arm/display/komeda/Makefile b/drivers/gpu/drm/arm/display/komeda/Makefile
index d7e29fc..73b8e8b 100644
--- a/drivers/gpu/drm/arm/display/komeda/Makefile
+++ b/drivers/gpu/drm/arm/display/komeda/Makefile
@@ -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 \
diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
index dfc70f5..b85514b 100644
--- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
+++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
@@ -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
index 0000000..9d14a92
--- /dev/null
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c
@@ -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
index 0000000..a2df218
--- /dev/null
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h
@@ -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
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_plane.c b/drivers/gpu/drm/arm/display/komeda/komeda_plane.c
index f344048..bcf30a7 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_plane.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_plane.c
@@ -135,6 +135,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;
 	}
@@ -330,6 +332,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);