drm/mediatek: Support reflect-y plane rotation
authorSean Paul <seanpaul@chromium.org>
Tue, 5 Nov 2019 21:10:22 +0000 (16:10 -0500)
committerCK Hu <ck.hu@mediatek.com>
Wed, 6 Nov 2019 08:00:44 +0000 (16:00 +0800)
Expose the rotation property and handle REFLECT_Y rotations.

Cc: Fritz Koenig <frkoenig@chromium.org>
Cc: Daniele Castagna <dcastagna@chromium.org>
Cc: Miguel Casas <mcasas@chromium.org>
Cc: Mark Yacoub <markyacoub@google.com>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: CK Hu <ck.hu@mediatek.com>
drivers/gpu/drm/mediatek/mtk_disp_ovl.c

index 14878eb..fae10ae 100644 (file)
@@ -3,6 +3,8 @@
  * Copyright (c) 2015 MediaTek Inc.
  */
 
+#include <drm/drm_fourcc.h>
+
 #include <linux/clk.h>
 #include <linux/component.h>
 #include <linux/module.h>
@@ -50,6 +52,7 @@
                                        OVL_CON_CLRFMT_RGB : 0)
 #define        OVL_CON_AEN             BIT(8)
 #define        OVL_CON_ALPHA           0xff
+#define        OVL_CON_VIRT_FLIP       BIT(9)
 
 struct mtk_disp_ovl_data {
        unsigned int addr;
@@ -137,6 +140,38 @@ static unsigned int mtk_ovl_layer_nr(struct mtk_ddp_comp *comp)
        return ovl->data->layer_nr;
 }
 
+static unsigned int mtk_ovl_supported_rotations(struct mtk_ddp_comp *comp)
+{
+       return DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y;
+}
+
+static int mtk_ovl_layer_check(struct mtk_ddp_comp *comp, unsigned int idx,
+                              struct mtk_plane_state *mtk_state)
+{
+       struct drm_plane_state *state = &mtk_state->base;
+       unsigned int rotation = 0;
+
+       rotation = drm_rotation_simplify(state->rotation,
+                                        DRM_MODE_ROTATE_0 |
+                                        DRM_MODE_REFLECT_Y);
+       rotation &= ~DRM_MODE_ROTATE_0;
+
+       /* We can only do reflection, not rotation */
+       if ((rotation & DRM_MODE_ROTATE_MASK) != 0)
+               return -EINVAL;
+
+       /*
+        * TODO: Rotating/reflecting YUV buffers is not supported at this time.
+        *       Only RGB[AX] variants are supported.
+        */
+       if (state->fb->format->is_yuv && rotation != 0)
+               return -EINVAL;
+
+       state->rotation = rotation;
+
+       return 0;
+}
+
 static void mtk_ovl_layer_on(struct mtk_ddp_comp *comp, unsigned int idx)
 {
        unsigned int reg;
@@ -229,6 +264,11 @@ static void mtk_ovl_layer_config(struct mtk_ddp_comp *comp, unsigned int idx,
        if (idx != 0)
                con |= OVL_CON_AEN | OVL_CON_ALPHA;
 
+       if (pending->rotation & DRM_MODE_REFLECT_Y) {
+               con |= OVL_CON_VIRT_FLIP;
+               addr += (pending->height - 1) * pending->pitch;
+       }
+
        writel_relaxed(con, comp->regs + DISP_REG_OVL_CON(idx));
        writel_relaxed(pitch, comp->regs + DISP_REG_OVL_PITCH(idx));
        writel_relaxed(src_size, comp->regs + DISP_REG_OVL_SRC_SIZE(idx));
@@ -263,9 +303,11 @@ static const struct mtk_ddp_comp_funcs mtk_disp_ovl_funcs = {
        .stop = mtk_ovl_stop,
        .enable_vblank = mtk_ovl_enable_vblank,
        .disable_vblank = mtk_ovl_disable_vblank,
+       .supported_rotations = mtk_ovl_supported_rotations,
        .layer_nr = mtk_ovl_layer_nr,
        .layer_on = mtk_ovl_layer_on,
        .layer_off = mtk_ovl_layer_off,
+       .layer_check = mtk_ovl_layer_check,
        .layer_config = mtk_ovl_layer_config,
        .bgclr_in_on = mtk_ovl_bgclr_in_on,
        .bgclr_in_off = mtk_ovl_bgclr_in_off,