drm/sun4i: backend: Check that we only have a single YUV plane
authorMaxime Ripard <maxime.ripard@bootlin.com>
Thu, 1 Mar 2018 19:18:45 +0000 (20:18 +0100)
committerMaxime Ripard <maxime.ripard@bootlin.com>
Mon, 19 Mar 2018 15:36:21 +0000 (16:36 +0100)
Just like for the frontend, a single plane can use a YUV format. Make sure
we have that constraint covered in our atomic_check.

This is preliminary to the actual YUV support to make sure we don't end up
in an impossible to support situation.

Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
Link: https://patchwork.freedesktop.org/patch/msgid/2f8586493d9139b12efe7e94f65e9a149f818e0e.1519931807.git-series.maxime.ripard@bootlin.com
drivers/gpu/drm/sun4i/sun4i_backend.c
drivers/gpu/drm/sun4i/sun4i_backend.h

index ed36240048d5436dfcd1450919b710f5d01c7ecd..8aaa74d099546ce38dc255238259c69a1828b73f 100644 (file)
@@ -42,6 +42,38 @@ static const u32 sunxi_rgb2yuv_coef[12] = {
        0x000001c1, 0x00003e88, 0x00003fb8, 0x00000808
 };
 
+static inline bool sun4i_backend_format_is_planar_yuv(uint32_t format)
+{
+       switch (format) {
+       case DRM_FORMAT_YUV411:
+       case DRM_FORMAT_YUV422:
+       case DRM_FORMAT_YUV444:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static inline bool sun4i_backend_format_is_packed_yuv422(uint32_t format)
+{
+       switch (format) {
+       case DRM_FORMAT_YUYV:
+       case DRM_FORMAT_YVYU:
+       case DRM_FORMAT_UYVY:
+       case DRM_FORMAT_VYUY:
+               return true;
+
+       default:
+               return false;
+       }
+}
+
+static inline bool sun4i_backend_format_is_yuv(uint32_t format)
+{
+       return sun4i_backend_format_is_planar_yuv(format) ||
+               sun4i_backend_format_is_packed_yuv422(format);
+}
+
 static void sun4i_backend_apply_color_correction(struct sunxi_engine *engine)
 {
        int i;
@@ -330,6 +362,7 @@ static int sun4i_backend_atomic_check(struct sunxi_engine *engine,
        unsigned int num_planes = 0;
        unsigned int num_alpha_planes = 0;
        unsigned int num_frontend_planes = 0;
+       unsigned int num_yuv_planes = 0;
        unsigned int current_pipe = 0;
        unsigned int i;
 
@@ -362,6 +395,11 @@ static int sun4i_backend_atomic_check(struct sunxi_engine *engine,
                if (fb->format->has_alpha)
                        num_alpha_planes++;
 
+               if (sun4i_backend_format_is_yuv(fb->format->format)) {
+                       DRM_DEBUG_DRIVER("Plane FB format is YUV\n");
+                       num_yuv_planes++;
+               }
+
                DRM_DEBUG_DRIVER("Plane zpos is %d\n",
                                 plane_state->normalized_zpos);
 
@@ -430,13 +468,20 @@ static int sun4i_backend_atomic_check(struct sunxi_engine *engine,
                s_state->pipe = current_pipe;
        }
 
+       /* We can only have a single YUV plane at a time */
+       if (num_yuv_planes > SUN4I_BACKEND_NUM_YUV_PLANES) {
+               DRM_DEBUG_DRIVER("Too many planes with YUV, rejecting...\n");
+               return -EINVAL;
+       }
+
        if (num_frontend_planes > SUN4I_BACKEND_NUM_FRONTEND_LAYERS) {
                DRM_DEBUG_DRIVER("Too many planes going through the frontend, rejecting\n");
                return -EINVAL;
        }
 
-       DRM_DEBUG_DRIVER("State valid with %u planes, %u alpha, %u video\n",
-                        num_planes, num_alpha_planes, num_frontend_planes);
+       DRM_DEBUG_DRIVER("State valid with %u planes, %u alpha, %u video, %u YUV\n",
+                        num_planes, num_alpha_planes, num_frontend_planes,
+                        num_yuv_planes);
 
        return 0;
 }
index 52e77591186acb4356f965a93bc060e8857c0f79..835408281309b93cc7c7ac77f7ec26e0eaeeffbd 100644 (file)
 #define SUN4I_BACKEND_NUM_LAYERS               4
 #define SUN4I_BACKEND_NUM_ALPHA_LAYERS         1
 #define SUN4I_BACKEND_NUM_FRONTEND_LAYERS      1
+#define SUN4I_BACKEND_NUM_YUV_PLANES           1
 
 struct sun4i_backend {
        struct sunxi_engine     engine;