diff mbox

[08/16] drm/omap: add format_is_yuv() helper

Message ID 1493893412-12178-9-git-send-email-tomi.valkeinen@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Tomi Valkeinen May 4, 2017, 10:23 a.m. UTC
In a few places the dispc driver needs to know whether the pixel format
is an YUV format. Add a helper to figure that out.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
---
 drivers/gpu/drm/omapdrm/dss/dispc.c | 56 +++++++++++++++----------------------
 1 file changed, 23 insertions(+), 33 deletions(-)

Comments

Laurent Pinchart May 24, 2017, 9:38 a.m. UTC | #1
Hi Tomi,

Thank you for the patch.

On Thursday 04 May 2017 13:23:24 Tomi Valkeinen wrote:
> In a few places the dispc driver needs to know whether the pixel format
> is an YUV format. Add a helper to figure that out.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
> ---
>  drivers/gpu/drm/omapdrm/dss/dispc.c | 56 ++++++++++++++--------------------
>  1 file changed, 23 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/gpu/drm/omapdrm/dss/dispc.c
> b/drivers/gpu/drm/omapdrm/dss/dispc.c index 48bb71eafa56..9dfef8fdff67
> 100644
> --- a/drivers/gpu/drm/omapdrm/dss/dispc.c
> +++ b/drivers/gpu/drm/omapdrm/dss/dispc.c
> @@ -978,6 +978,18 @@ static void dispc_ovl_set_color_mode(enum omap_plane_id
> plane, REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
>  }
> 
> +static bool format_is_yuv(enum omap_color_mode color_mode)
> +{
> +	switch (color_mode) {
> +	case OMAP_DSS_COLOR_YUV2:
> +	case OMAP_DSS_COLOR_UYVY:
> +	case OMAP_DSS_COLOR_NV12:
> +		return true;
> +	default:
> +		return false;
> +	}
> +}
> +
>  static void dispc_ovl_configure_burst_type(enum omap_plane_id plane,
>  		enum omap_dss_rotation_type rotation_type)
>  {
> @@ -1703,9 +1715,8 @@ static void dispc_ovl_set_scaling_uv(enum
> omap_plane_id plane,
> 
>  	if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
>  		return;
> -	if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
> -			color_mode != OMAP_DSS_COLOR_UYVY &&
> -			color_mode != OMAP_DSS_COLOR_NV12)) {
> +
> +	if (!format_is_yuv(color_mode)) {
>  		/* reset chroma resampling for RGB formats  */
>  		if (plane != OMAP_DSS_WB)
>  			REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
> @@ -2384,19 +2395,9 @@ static int dispc_ovl_setup_common(enum omap_plane_id
> plane, if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
>  		return -EINVAL;
> 
> -	switch (color_mode) {
> -	case OMAP_DSS_COLOR_YUV2:
> -	case OMAP_DSS_COLOR_UYVY:
> -	case OMAP_DSS_COLOR_NV12:
> -		if (in_width & 1) {
> -			DSSERR("input width %d is not even for YUV format\n",
> -				in_width);
> -			return -EINVAL;
> -		}
> -		break;
> -
> -	default:
> -		break;
> +	if (format_is_yuv(color_mode) && (in_width & 1)) {
> +		DSSERR("input width %d is not even for YUV format\n", 
in_width);
> +		return -EINVAL;
>  	}

This is a condition that should be checked by omapdrm in the atomic_check 
phase, to avoid returning an error in the atomic_commit phase.

>  	out_width = out_width == 0 ? width : out_width;
> @@ -2433,26 +2434,15 @@ static int dispc_ovl_setup_common(enum omap_plane_id
> plane, DSSDBG("predecimation %d x %x, new input size %d x %d\n",
>  			x_predecim, y_predecim, in_width, in_height);
> 
> -	switch (color_mode) {
> -	case OMAP_DSS_COLOR_YUV2:
> -	case OMAP_DSS_COLOR_UYVY:
> -	case OMAP_DSS_COLOR_NV12:
> -		if (in_width & 1) {
> -			DSSDBG("predecimated input width is not even for YUV 
format\n");
> -			DSSDBG("adjusting input width %d -> %d\n",
> -				in_width, in_width & ~1);
> -
> -			in_width &= ~1;
> -		}
> -		break;
> +	if (format_is_yuv(color_mode) && (in_width & 1)) {
> +		DSSDBG("predecimated input width is not even for YUV 
format\n");
> +		DSSDBG("adjusting input width %d -> %d\n",
> +			in_width, in_width & ~1);
> 
> -	default:
> -		break;
> +		in_width &= ~1;
>  	}

Same here.

We can fix that as a follow-up patch, so

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> -	if (color_mode == OMAP_DSS_COLOR_YUV2 ||
> -			color_mode == OMAP_DSS_COLOR_UYVY ||
> -			color_mode == OMAP_DSS_COLOR_NV12)
> +	if (format_is_yuv(color_mode))
>  		cconv = 1;
> 
>  	if (ilace && !fieldmode) {
diff mbox

Patch

diff --git a/drivers/gpu/drm/omapdrm/dss/dispc.c b/drivers/gpu/drm/omapdrm/dss/dispc.c
index 48bb71eafa56..9dfef8fdff67 100644
--- a/drivers/gpu/drm/omapdrm/dss/dispc.c
+++ b/drivers/gpu/drm/omapdrm/dss/dispc.c
@@ -978,6 +978,18 @@  static void dispc_ovl_set_color_mode(enum omap_plane_id plane,
 	REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
 }
 
+static bool format_is_yuv(enum omap_color_mode color_mode)
+{
+	switch (color_mode) {
+	case OMAP_DSS_COLOR_YUV2:
+	case OMAP_DSS_COLOR_UYVY:
+	case OMAP_DSS_COLOR_NV12:
+		return true;
+	default:
+		return false;
+	}
+}
+
 static void dispc_ovl_configure_burst_type(enum omap_plane_id plane,
 		enum omap_dss_rotation_type rotation_type)
 {
@@ -1703,9 +1715,8 @@  static void dispc_ovl_set_scaling_uv(enum omap_plane_id plane,
 
 	if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
 		return;
-	if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
-			color_mode != OMAP_DSS_COLOR_UYVY &&
-			color_mode != OMAP_DSS_COLOR_NV12)) {
+
+	if (!format_is_yuv(color_mode)) {
 		/* reset chroma resampling for RGB formats  */
 		if (plane != OMAP_DSS_WB)
 			REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
@@ -2384,19 +2395,9 @@  static int dispc_ovl_setup_common(enum omap_plane_id plane,
 	if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
 		return -EINVAL;
 
-	switch (color_mode) {
-	case OMAP_DSS_COLOR_YUV2:
-	case OMAP_DSS_COLOR_UYVY:
-	case OMAP_DSS_COLOR_NV12:
-		if (in_width & 1) {
-			DSSERR("input width %d is not even for YUV format\n",
-				in_width);
-			return -EINVAL;
-		}
-		break;
-
-	default:
-		break;
+	if (format_is_yuv(color_mode) && (in_width & 1)) {
+		DSSERR("input width %d is not even for YUV format\n", in_width);
+		return -EINVAL;
 	}
 
 	out_width = out_width == 0 ? width : out_width;
@@ -2433,26 +2434,15 @@  static int dispc_ovl_setup_common(enum omap_plane_id plane,
 		DSSDBG("predecimation %d x %x, new input size %d x %d\n",
 			x_predecim, y_predecim, in_width, in_height);
 
-	switch (color_mode) {
-	case OMAP_DSS_COLOR_YUV2:
-	case OMAP_DSS_COLOR_UYVY:
-	case OMAP_DSS_COLOR_NV12:
-		if (in_width & 1) {
-			DSSDBG("predecimated input width is not even for YUV format\n");
-			DSSDBG("adjusting input width %d -> %d\n",
-				in_width, in_width & ~1);
-
-			in_width &= ~1;
-		}
-		break;
+	if (format_is_yuv(color_mode) && (in_width & 1)) {
+		DSSDBG("predecimated input width is not even for YUV format\n");
+		DSSDBG("adjusting input width %d -> %d\n",
+			in_width, in_width & ~1);
 
-	default:
-		break;
+		in_width &= ~1;
 	}
 
-	if (color_mode == OMAP_DSS_COLOR_YUV2 ||
-			color_mode == OMAP_DSS_COLOR_UYVY ||
-			color_mode == OMAP_DSS_COLOR_NV12)
+	if (format_is_yuv(color_mode))
 		cconv = 1;
 
 	if (ilace && !fieldmode) {