Skip to contentSkip to conversation

drm/mediatek: Support reflect-y plane rotation

PATCH In review Sean Paul 3 participants 5 messages Nov 1, 2019 – Nov 5, 2019

Subsystems (3)
lore
Share & tools
lore

Sean Paul

author
#0 lore raw

PATCH 1/1 drm/mediatek: Support reflect-y plane rotation

From: Sean Paul <[email protected]>

Expose the rotation property and handle REFLECT_Y rotations.

Cc Fritz Koenig <[email protected]>
Cc Daniele Castagna <[email protected]>
Cc Miguel Casas <[email protected]>
Cc Mark Yacoub <[email protected]>

---

The hardware also supports REFLECT_X, but I just could not figure out how to get it working. If someone is interested in getting this going, I'm happy to share notes and my WIP patch. For now, though, I actually only need y-flip so I'm giving up on x-flip.

 drivers/gpu/drm/mediatek/mtk_disp_ovl.c  |  6 ++++++
 drivers/gpu/drm/mediatek/mtk_drm_plane.c | 11 ++++++++++-
 drivers/gpu/drm/mediatek/mtk_drm_plane.h |  1 +
 3 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +6 -0
index 14878ebf59d7..6505479ee506 100644
@@ -50,6 +50,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;
@@ -229,6 +230,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));
drivers/gpu/drm/mediatek/mtk_drm_plane.c +10 -1
index 584a9ecadce6..4d8f2b55334b 100644
@@ -88,6 +88,9 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
 	if (!fb)
 		return 0;
 
+	if (fb->format->is_yuv && (state->rotation & ~DRM_MODE_ROTATE_0) != 0)
+		return -EINVAL;
+
 	if (!state->crtc)
 		return 0;
 
@@ -132,6 +135,7 @@ static void mtk_plane_atomic_update(struct drm_plane *plane,
 	state->pending.y = plane->state->dst.y1;
 	state->pending.width = drm_rect_width(&plane->state->dst);
 	state->pending.height = drm_rect_height(&plane->state->dst);
+	state->pending.rotation = plane->state->rotation;
 	wmb(); /* Make sure the above parameters are set before update */
 	state->pending.dirty = true;
 }
@@ -166,7 +170,12 @@ int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,
 		return err;
 	}
 
-	drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
+	err = drm_plane_create_rotation_property(plane, 0,
+						 DRM_MODE_ROTATE_0 |
+						 DRM_MODE_REFLECT_Y);
+	if (err)
+		DRM_INFO("Create rotation property failed, continuing...\n");
 
+	drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
 	return 0;
 }
drivers/gpu/drm/mediatek/mtk_drm_plane.h +1 -0
index 6f842df722c7..83b634a997cc 100644
@@ -20,6 +20,7 @@ struct mtk_plane_pending_state {
 	unsigned int			y;
 	unsigned int			width;
 	unsigned int			height;
+	unsigned int			rotation;
 	bool				dirty;
 };
 
Signature · 6 lines
Sean Paul, Software Engineer, Google / Chromium OS

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

Tested it on my end and confirmed that it works as intended.

Quoted 98 lines · Sean Paul

From: Sean Paul <[email protected]>

Expose the rotation property and handle REFLECT_Y rotations.

Cc Fritz Koenig <[email protected]>
Cc Daniele Castagna <[email protected]>
Cc Miguel Casas <[email protected]>
Cc Mark Yacoub <[email protected]>

---

The hardware also supports REFLECT_X, but I just could not figure out how to get it working. If someone is interested in getting this going, I'm happy to share notes and my WIP patch. For now, though, I actually only need y-flip so I'm giving up on x-flip.

 drivers/gpu/drm/mediatek/mtk_disp_ovl.c  |  6 ++++++
 drivers/gpu/drm/mediatek/mtk_drm_plane.c | 11 ++++++++++-
 drivers/gpu/drm/mediatek/mtk_drm_plane.h |  1 +
 3 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +6 -0
index 14878ebf59d7..6505479ee506 100644
@@ -50,6 +50,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;
@@ -229,6 +230,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));
drivers/gpu/drm/mediatek/mtk_drm_plane.c +10 -1
index 584a9ecadce6..4d8f2b55334b 100644
@@ -88,6 +88,9 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
        if (!fb)
                return 0;
 
+       if (fb->format->is_yuv && (state->rotation & ~DRM_MODE_ROTATE_0) != 0)
+               return -EINVAL;
+
        if (!state->crtc)
                return 0;
 
@@ -132,6 +135,7 @@ static void mtk_plane_atomic_update(struct drm_plane *plane,
        state->pending.y = plane->state->dst.y1;
        state->pending.width = drm_rect_width(&plane->state->dst);
        state->pending.height = drm_rect_height(&plane->state->dst);
+       state->pending.rotation = plane->state->rotation;
        wmb(); /* Make sure the above parameters are set before update */
        state->pending.dirty = true;
 }
@@ -166,7 +170,12 @@ int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,
                return err;
        }
 
-       drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
+       err = drm_plane_create_rotation_property(plane, 0,
+                                                DRM_MODE_ROTATE_0 |
+                                                DRM_MODE_REFLECT_Y);
+       if (err)
+               DRM_INFO("Create rotation property failed, continuing...\n");
 
+       drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
        return 0;
 }
drivers/gpu/drm/mediatek/mtk_drm_plane.h +1 -1
index 6f842df722c7..83b634a997cc 100644
@@ -20,6 +20,7 @@ struct mtk_plane_pending_state {
        unsigned int                    y;
        unsigned int                    width;
        unsigned int                    height;
+       unsigned int                    rotation;
        bool                            dirty;
 };
 
--

Sean Paul, Software Engineer, Google / Chromium OS

#2 lore raw
In reply to Sean Paul

Hi, Sean:

Quoted 9 lines · Sean Paul

From: Sean Paul <[email protected]>

Expose the rotation property and handle REFLECT_Y rotations.

Cc Fritz Koenig <[email protected]>
Cc Daniele Castagna <[email protected]>
Cc Miguel Casas <[email protected]>
Cc Mark Yacoub <[email protected]>
Quoted 6 lines

---

The hardware also supports REFLECT_X, but I just could not figure out how to get it working. If someone is interested in getting this going, I'm happy to share notes and my WIP patch. For now, though, I actually only need y-flip so I'm giving up on x-flip.

Does [1] give you any hint for x-flip, or that patch is incorrect?

[1]
https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1533519

Quoted 36 lines

 drivers/gpu/drm/mediatek/mtk_disp_ovl.c  |  6 ++++++
 drivers/gpu/drm/mediatek/mtk_drm_plane.c | 11 ++++++++++-
 drivers/gpu/drm/mediatek/mtk_drm_plane.h |  1 +
 3 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +6 -0
index 14878ebf59d7..6505479ee506 100644
@@ -50,6 +50,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;
@@ -229,6 +230,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));
drivers/gpu/drm/mediatek/mtk_drm_plane.c +0 -0
index 584a9ecadce6..4d8f2b55334b 100644

drivers/gpu/drm/mediatek/mtk_drm_plane.c static int mtk_plane_atomic_check(struct drm_plane *plane, · line 92

Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.c +2 -0
@@ -88,6 +88,9 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
 	if (!fb)
 		return 0;
 
+	if (fb->format->is_yuv && (state->rotation & ~DRM_MODE_ROTATE_0) != 0)
+		return -EINVAL;

If this patch does not support all color format, please describe what color format does this patch support, so others could try to make the rest color format work.

Regards,
CK

Quoted 31 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.c +8 -1
+
 	if (!state->crtc)
 		return 0;
 
@@ -132,6 +135,7 @@ static void mtk_plane_atomic_update(struct drm_plane *plane,
 	state->pending.y = plane->state->dst.y1;
 	state->pending.width = drm_rect_width(&plane->state->dst);
 	state->pending.height = drm_rect_height(&plane->state->dst);
+	state->pending.rotation = plane->state->rotation;
 	wmb(); /* Make sure the above parameters are set before update */
 	state->pending.dirty = true;
 }
@@ -166,7 +170,12 @@ int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,
 		return err;
 	}
 
-	drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
+	err = drm_plane_create_rotation_property(plane, 0,
+						 DRM_MODE_ROTATE_0 |
+						 DRM_MODE_REFLECT_Y);
+	if (err)
+		DRM_INFO("Create rotation property failed, continuing...\n");
 
+	drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
 	return 0;
 }
drivers/gpu/drm/mediatek/mtk_drm_plane.h +0 -0
index 6f842df722c7..83b634a997cc 100644

drivers/gpu/drm/mediatek/mtk_drm_plane.h struct mtk_plane_pending_state { · line 26

Quoted 7 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.h +1 -0
@@ -20,6 +20,7 @@ struct mtk_plane_pending_state {
 	unsigned int			y;
 	unsigned int			width;
 	unsigned int			height;
+	unsigned int			rotation;
 	bool				dirty;
 };
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author
#3 lore raw
Quoted 19 lines · CK Hu

Hi, Sean:

Quoted 9 lines · Sean Paul

From: Sean Paul <[email protected]>

Expose the rotation property and handle REFLECT_Y rotations.

Cc Fritz Koenig <[email protected]>
Cc Daniele Castagna <[email protected]>
Cc Miguel Casas <[email protected]>
Cc Mark Yacoub <[email protected]>
Quoted 6 lines

---

The hardware also supports REFLECT_X, but I just could not figure out how to get it working. If someone is interested in getting this going, I'm happy to share notes and my WIP patch. For now, though, I actually only need y-flip so I'm giving up on x-flip.

Quoted 5 lines

Does [1] give you any hint for x-flip, or that patch is incorrect?

[1]
https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1533519

Hi CK,
Thank you for the pointer, that did help! That patch is slightly incorrect, but pointed me to the issue I was having with REFLECT_X. I'll upload a new set with REFLECT_X and ROTATE_180 support shortly.

Sean

Quoted 89 lines
Quoted 36 lines

 drivers/gpu/drm/mediatek/mtk_disp_ovl.c  |  6 ++++++
 drivers/gpu/drm/mediatek/mtk_drm_plane.c | 11 ++++++++++-
 drivers/gpu/drm/mediatek/mtk_drm_plane.h |  1 +
 3 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +6 -0
index 14878ebf59d7..6505479ee506 100644
@@ -50,6 +50,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;
@@ -229,6 +230,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));
drivers/gpu/drm/mediatek/mtk_drm_plane.c +0 -0
index 584a9ecadce6..4d8f2b55334b 100644

drivers/gpu/drm/mediatek/mtk_drm_plane.c static int mtk_plane_atomic_check(struct drm_plane *plane, · line 92

Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.c +2 -0
@@ -88,6 +88,9 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
 	if (!fb)
 		return 0;
 
+	if (fb->format->is_yuv && (state->rotation & ~DRM_MODE_ROTATE_0) != 0)
+		return -EINVAL;

If this patch does not support all color format, please describe what color format does this patch support, so others could try to make the rest color format work.

Regards,
CK

Quoted 38 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.c +8 -1
+
 	if (!state->crtc)
 		return 0;
 
@@ -132,6 +135,7 @@ static void mtk_plane_atomic_update(struct drm_plane *plane,
 	state->pending.y = plane->state->dst.y1;
 	state->pending.width = drm_rect_width(&plane->state->dst);
 	state->pending.height = drm_rect_height(&plane->state->dst);
+	state->pending.rotation = plane->state->rotation;
 	wmb(); /* Make sure the above parameters are set before update */
 	state->pending.dirty = true;
 }
@@ -166,7 +170,12 @@ int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,
 		return err;
 	}
 
-	drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
+	err = drm_plane_create_rotation_property(plane, 0,
+						 DRM_MODE_ROTATE_0 |
+						 DRM_MODE_REFLECT_Y);
+	if (err)
+		DRM_INFO("Create rotation property failed, continuing...\n");
 
+	drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
 	return 0;
 }
drivers/gpu/drm/mediatek/mtk_drm_plane.h +1 -0
index 6f842df722c7..83b634a997cc 100644
@@ -20,6 +20,7 @@ struct mtk_plane_pending_state {
 	unsigned int			y;
 	unsigned int			width;
 	unsigned int			height;
+	unsigned int			rotation;
 	bool				dirty;
 };
 
Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OS
#4 lore raw
In reply to Sean Paul

Hi, Sean:

Quoted 51 lines · Sean Paul

From: Sean Paul <[email protected]>

Expose the rotation property and handle REFLECT_Y rotations.

Cc Fritz Koenig <[email protected]>
Cc Daniele Castagna <[email protected]>
Cc Miguel Casas <[email protected]>
Cc Mark Yacoub <[email protected]>

---

The hardware also supports REFLECT_X, but I just could not figure out how to get it working. If someone is interested in getting this going, I'm happy to share notes and my WIP patch. For now, though, I actually only need y-flip so I'm giving up on x-flip.

 drivers/gpu/drm/mediatek/mtk_disp_ovl.c  |  6 ++++++
 drivers/gpu/drm/mediatek/mtk_drm_plane.c | 11 ++++++++++-
 drivers/gpu/drm/mediatek/mtk_drm_plane.h |  1 +
 3 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +6 -0
index 14878ebf59d7..6505479ee506 100644
@@ -50,6 +50,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;
@@ -229,6 +230,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));
drivers/gpu/drm/mediatek/mtk_drm_plane.c +0 -0
index 584a9ecadce6..4d8f2b55334b 100644

drivers/gpu/drm/mediatek/mtk_drm_plane.c static int mtk_plane_atomic_check(struct drm_plane *plane, · line 93

Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.c +3 -0
@@ -88,6 +88,9 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
 	if (!fb)
 		return 0;
 
+	if (fb->format->is_yuv && (state->rotation & ~DRM_MODE_ROTATE_0) != 0)
+		return -EINVAL;
+

For some crtc, its DMA component (first component in crtc pipe line which read data from DRAM) may be RDMA [1]. It does not support RDMA reflect function in this patch, so need to do something to protect this case. Maybe we should check this plane is bind to a crtc whose DMA component support reflect or not.

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/mediatek/mtk_drm_drv.c?h=v5.4-rc6#n133

Regards,
CK

Quoted 30 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.c +7 -1
 	if (!state->crtc)
 		return 0;
 
@@ -132,6 +135,7 @@ static void mtk_plane_atomic_update(struct drm_plane *plane,
 	state->pending.y = plane->state->dst.y1;
 	state->pending.width = drm_rect_width(&plane->state->dst);
 	state->pending.height = drm_rect_height(&plane->state->dst);
+	state->pending.rotation = plane->state->rotation;
 	wmb(); /* Make sure the above parameters are set before update */
 	state->pending.dirty = true;
 }
@@ -166,7 +170,12 @@ int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,
 		return err;
 	}
 
-	drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
+	err = drm_plane_create_rotation_property(plane, 0,
+						 DRM_MODE_ROTATE_0 |
+						 DRM_MODE_REFLECT_Y);
+	if (err)
+		DRM_INFO("Create rotation property failed, continuing...\n");
 
+	drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
 	return 0;
 }
drivers/gpu/drm/mediatek/mtk_drm_plane.h +0 -0
index 6f842df722c7..83b634a997cc 100644

drivers/gpu/drm/mediatek/mtk_drm_plane.h struct mtk_plane_pending_state { · line 26

Quoted 7 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.h +1 -0
@@ -20,6 +20,7 @@ struct mtk_plane_pending_state {
 	unsigned int			y;
 	unsigned int			width;
 	unsigned int			height;
+	unsigned int			rotation;
 	bool				dirty;
 };
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel