Skip to content

Commit 3246355

Browse files
committed
drm/sun4i: backend: Check that we only have a single YUV plane
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 <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/2f8586493d9139b12efe7e94f65e9a149f818e0e.1519931807.git-series.maxime.ripard@bootlin.com
1 parent 3347895 commit 3246355

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

drivers/gpu/drm/sun4i/sun4i_backend.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,38 @@ static const u32 sunxi_rgb2yuv_coef[12] = {
4242
0x000001c1, 0x00003e88, 0x00003fb8, 0x00000808
4343
};
4444

45+
static inline bool sun4i_backend_format_is_planar_yuv(uint32_t format)
46+
{
47+
switch (format) {
48+
case DRM_FORMAT_YUV411:
49+
case DRM_FORMAT_YUV422:
50+
case DRM_FORMAT_YUV444:
51+
return true;
52+
default:
53+
return false;
54+
}
55+
}
56+
57+
static inline bool sun4i_backend_format_is_packed_yuv422(uint32_t format)
58+
{
59+
switch (format) {
60+
case DRM_FORMAT_YUYV:
61+
case DRM_FORMAT_YVYU:
62+
case DRM_FORMAT_UYVY:
63+
case DRM_FORMAT_VYUY:
64+
return true;
65+
66+
default:
67+
return false;
68+
}
69+
}
70+
71+
static inline bool sun4i_backend_format_is_yuv(uint32_t format)
72+
{
73+
return sun4i_backend_format_is_planar_yuv(format) ||
74+
sun4i_backend_format_is_packed_yuv422(format);
75+
}
76+
4577
static void sun4i_backend_apply_color_correction(struct sunxi_engine *engine)
4678
{
4779
int i;
@@ -330,6 +362,7 @@ static int sun4i_backend_atomic_check(struct sunxi_engine *engine,
330362
unsigned int num_planes = 0;
331363
unsigned int num_alpha_planes = 0;
332364
unsigned int num_frontend_planes = 0;
365+
unsigned int num_yuv_planes = 0;
333366
unsigned int current_pipe = 0;
334367
unsigned int i;
335368

@@ -362,6 +395,11 @@ static int sun4i_backend_atomic_check(struct sunxi_engine *engine,
362395
if (fb->format->has_alpha)
363396
num_alpha_planes++;
364397

398+
if (sun4i_backend_format_is_yuv(fb->format->format)) {
399+
DRM_DEBUG_DRIVER("Plane FB format is YUV\n");
400+
num_yuv_planes++;
401+
}
402+
365403
DRM_DEBUG_DRIVER("Plane zpos is %d\n",
366404
plane_state->normalized_zpos);
367405

@@ -430,13 +468,20 @@ static int sun4i_backend_atomic_check(struct sunxi_engine *engine,
430468
s_state->pipe = current_pipe;
431469
}
432470

471+
/* We can only have a single YUV plane at a time */
472+
if (num_yuv_planes > SUN4I_BACKEND_NUM_YUV_PLANES) {
473+
DRM_DEBUG_DRIVER("Too many planes with YUV, rejecting...\n");
474+
return -EINVAL;
475+
}
476+
433477
if (num_frontend_planes > SUN4I_BACKEND_NUM_FRONTEND_LAYERS) {
434478
DRM_DEBUG_DRIVER("Too many planes going through the frontend, rejecting\n");
435479
return -EINVAL;
436480
}
437481

438-
DRM_DEBUG_DRIVER("State valid with %u planes, %u alpha, %u video\n",
439-
num_planes, num_alpha_planes, num_frontend_planes);
482+
DRM_DEBUG_DRIVER("State valid with %u planes, %u alpha, %u video, %u YUV\n",
483+
num_planes, num_alpha_planes, num_frontend_planes,
484+
num_yuv_planes);
440485

441486
return 0;
442487
}

drivers/gpu/drm/sun4i/sun4i_backend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
#define SUN4I_BACKEND_NUM_LAYERS 4
150150
#define SUN4I_BACKEND_NUM_ALPHA_LAYERS 1
151151
#define SUN4I_BACKEND_NUM_FRONTEND_LAYERS 1
152+
#define SUN4I_BACKEND_NUM_YUV_PLANES 1
152153

153154
struct sun4i_backend {
154155
struct sunxi_engine engine;

0 commit comments

Comments
 (0)