[PATCH 09/23] drm/exynos/vidi: embed exynos_drm_crtc directly into context

Andrzej Hajda a.hajda at samsung.com
Fri Mar 1 12:20:41 UTC 2019


Since crtc maps 1:1 to the device there is no point in allocating it
separately, another benefit is possibility of direct initialisation
of its fields which is more readable and allows further expansion.

Signed-off-by: Andrzej Hajda <a.hajda at samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_vidi.c | 26 +++++++++++++-----------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_vidi.c b/drivers/gpu/drm/exynos/exynos_drm_vidi.c
index b61ae3415b8c..377aae5f7631 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_vidi.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_vidi.c
@@ -41,7 +41,7 @@ struct vidi_context {
 	struct drm_encoder		encoder;
 	struct platform_device		*pdev;
 	struct drm_device		*drm_dev;
-	struct exynos_drm_crtc		*crtc;
+	struct exynos_drm_crtc		crtc;
 	struct drm_connector		connector;
 	struct exynos_drm_plane		planes[WINDOWS_NR];
 	struct edid			*raw_edid;
@@ -57,6 +57,8 @@ static inline struct vidi_context *encoder_to_vidi(struct drm_encoder *e)
 	return container_of(e, struct vidi_context, encoder);
 }
 
+#define to_vidi(ptr) container_of(ptr, struct vidi_context, ptr)
+
 static const char fake_edid_info[] = {
 	0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4c, 0x2d, 0x05, 0x05,
 	0x00, 0x00, 0x00, 0x00, 0x30, 0x12, 0x01, 0x03, 0x80, 0x10, 0x09, 0x78,
@@ -96,7 +98,7 @@ static const enum drm_plane_type vidi_win_types[WINDOWS_NR] = {
 
 static int vidi_enable_vblank(struct exynos_drm_crtc *crtc)
 {
-	struct vidi_context *ctx = crtc->ctx;
+	struct vidi_context *ctx = to_vidi(crtc);
 
 	if (ctx->suspended)
 		return -EPERM;
@@ -115,7 +117,7 @@ static void vidi_update_plane(struct exynos_drm_crtc *crtc,
 			      struct exynos_drm_plane *plane)
 {
 	struct drm_plane_state *state = plane->base.state;
-	struct vidi_context *ctx = crtc->ctx;
+	struct vidi_context *ctx = to_vidi(crtc);
 	dma_addr_t addr;
 
 	if (ctx->suspended)
@@ -127,7 +129,7 @@ static void vidi_update_plane(struct exynos_drm_crtc *crtc,
 
 static void vidi_enable(struct exynos_drm_crtc *crtc)
 {
-	struct vidi_context *ctx = crtc->ctx;
+	struct vidi_context *ctx = to_vidi(crtc);
 
 	mutex_lock(&ctx->lock);
 
@@ -140,7 +142,7 @@ static void vidi_enable(struct exynos_drm_crtc *crtc)
 
 static void vidi_disable(struct exynos_drm_crtc *crtc)
 {
-	struct vidi_context *ctx = crtc->ctx;
+	struct vidi_context *ctx = to_vidi(crtc);
 
 	drm_crtc_vblank_off(&crtc->base);
 
@@ -164,7 +166,7 @@ static void vidi_fake_vblank_timer(struct timer_list *t)
 {
 	struct vidi_context *ctx = from_timer(ctx, t, timer);
 
-	if (drm_crtc_handle_vblank(&ctx->crtc->base))
+	if (drm_crtc_handle_vblank(&ctx->crtc.base))
 		mod_timer(&ctx->timer,
 			jiffies + msecs_to_jiffies(VIDI_REFRESH_TIME) - 1);
 }
@@ -377,7 +379,6 @@ static int vidi_bind(struct device *dev, struct device *master, void *data)
 	struct vidi_context *ctx = dev_get_drvdata(dev);
 	struct drm_device *drm_dev = data;
 	struct drm_encoder *encoder = &ctx->encoder;
-	struct exynos_drm_plane *exynos_plane;
 	unsigned int i;
 	int ret;
 
@@ -390,13 +391,14 @@ static int vidi_bind(struct device *dev, struct device *master, void *data)
 			return ret;
 	}
 
-	exynos_plane = &ctx->planes[DEFAULT_WIN];
-	ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
-			EXYNOS_DISPLAY_TYPE_VIDI, &vidi_crtc_ops, ctx);
-	if (IS_ERR(ctx->crtc)) {
+	ctx->crtc.type = EXYNOS_DISPLAY_TYPE_VIDI;
+	ctx->crtc.ops = &vidi_crtc_ops;
+	ret = exynos_drm_crtc_init(&ctx->crtc, drm_dev);
+	if (ret) {
 		DRM_ERROR("failed to create crtc.\n");
-		return PTR_ERR(ctx->crtc);
+		return ret;
 	}
+	ctx->crtc.base.primary = &ctx->planes[DEFAULT_WIN].base;
 
 	drm_encoder_init(drm_dev, encoder, &exynos_vidi_encoder_funcs,
 			 DRM_MODE_ENCODER_TMDS, NULL);
-- 
2.17.1



More information about the dri-devel mailing list