[PATCH v2 RESEND 08/24] drm/exynos/mixer: embed exynos_drm_crtc directly into context

Andrzej Hajda a.hajda at samsung.com
Wed Mar 20 13:06:51 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_mixer.c | 39 ++++++++++++++-------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_mixer.c b/drivers/gpu/drm/exynos/exynos_mixer.c
index 750f682e9c31..946d62ae83e3 100644
--- a/drivers/gpu/drm/exynos/exynos_mixer.c
+++ b/drivers/gpu/drm/exynos/exynos_mixer.c
@@ -98,7 +98,7 @@ struct mixer_context {
 	struct platform_device *pdev;
 	struct device		*dev;
 	struct drm_device	*drm_dev;
-	struct exynos_drm_crtc	*crtc;
+	struct exynos_drm_crtc	crtc;
 	struct exynos_drm_plane	planes[MIXER_WIN_NR];
 	unsigned long		flags;
 
@@ -116,6 +116,8 @@ struct mixer_context {
 	int			scan_value;
 };
 
+#define to_mixer(ptr) container_of(ptr, struct mixer_context, ptr)
+
 struct mixer_drv_data {
 	enum mixer_version_id	version;
 	bool					is_vp_enabled;
@@ -426,7 +428,7 @@ static void mixer_stop(struct mixer_context *ctx)
 
 static void mixer_commit(struct mixer_context *ctx)
 {
-	struct drm_display_mode *mode = &ctx->crtc->base.state->adjusted_mode;
+	struct drm_display_mode *mode = &ctx->crtc.base.state->adjusted_mode;
 
 	mixer_cfg_scan(ctx, mode->hdisplay, mode->vdisplay);
 	mixer_cfg_rgb_fmt(ctx, mode);
@@ -712,7 +714,7 @@ static irqreturn_t mixer_irq_handler(int irq, void *arg)
 				goto out;
 		}
 
-		drm_crtc_handle_vblank(&ctx->crtc->base);
+		drm_crtc_handle_vblank(&ctx->crtc.base);
 	}
 
 out:
@@ -856,7 +858,7 @@ static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
 
 static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
 {
-	struct mixer_context *mixer_ctx = crtc->ctx;
+	struct mixer_context *mixer_ctx = to_mixer(crtc);
 
 	__set_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
@@ -871,7 +873,7 @@ static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)
 
 static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
 {
-	struct mixer_context *mixer_ctx = crtc->ctx;
+	struct mixer_context *mixer_ctx = to_mixer(crtc);
 
 	__clear_bit(MXR_BIT_VSYNC, &mixer_ctx->flags);
 
@@ -885,7 +887,7 @@ static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
 
 static void mixer_atomic_begin(struct exynos_drm_crtc *crtc)
 {
-	struct mixer_context *mixer_ctx = crtc->ctx;
+	struct mixer_context *mixer_ctx = to_mixer(crtc);
 
 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
 		return;
@@ -896,7 +898,7 @@ static void mixer_atomic_begin(struct exynos_drm_crtc *crtc)
 static void mixer_update_plane(struct exynos_drm_crtc *crtc,
 			       struct exynos_drm_plane *plane)
 {
-	struct mixer_context *mixer_ctx = crtc->ctx;
+	struct mixer_context *mixer_ctx = to_mixer(crtc);
 
 	DRM_DEBUG_KMS("win: %d\n", plane->index);
 
@@ -912,7 +914,7 @@ static void mixer_update_plane(struct exynos_drm_crtc *crtc,
 static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
 				struct exynos_drm_plane *plane)
 {
-	struct mixer_context *mixer_ctx = crtc->ctx;
+	struct mixer_context *mixer_ctx = to_mixer(crtc);
 	unsigned long flags;
 
 	DRM_DEBUG_KMS("win: %d\n", plane->index);
@@ -927,7 +929,7 @@ static void mixer_disable_plane(struct exynos_drm_crtc *crtc,
 
 static void mixer_atomic_flush(struct exynos_drm_crtc *crtc)
 {
-	struct mixer_context *mixer_ctx = crtc->ctx;
+	struct mixer_context *mixer_ctx = to_mixer(crtc);
 
 	if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
 		return;
@@ -938,7 +940,7 @@ static void mixer_atomic_flush(struct exynos_drm_crtc *crtc)
 
 static void mixer_enable(struct exynos_drm_crtc *crtc)
 {
-	struct mixer_context *ctx = crtc->ctx;
+	struct mixer_context *ctx = to_mixer(crtc);
 
 	if (test_bit(MXR_BIT_POWERED, &ctx->flags))
 		return;
@@ -967,7 +969,7 @@ static void mixer_enable(struct exynos_drm_crtc *crtc)
 
 static void mixer_disable(struct exynos_drm_crtc *crtc)
 {
-	struct mixer_context *ctx = crtc->ctx;
+	struct mixer_context *ctx = to_mixer(crtc);
 	int i;
 
 	if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
@@ -989,7 +991,7 @@ static void mixer_disable(struct exynos_drm_crtc *crtc)
 static int mixer_mode_valid(struct exynos_drm_crtc *crtc,
 		const struct drm_display_mode *mode)
 {
-	struct mixer_context *ctx = crtc->ctx;
+	struct mixer_context *ctx = to_mixer(crtc);
 	u32 w = mode->hdisplay, h = mode->vdisplay;
 
 	DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d\n", w, h,
@@ -1015,7 +1017,7 @@ static bool mixer_mode_fixup(struct exynos_drm_crtc *crtc,
 		   const struct drm_display_mode *mode,
 		   struct drm_display_mode *adjusted_mode)
 {
-	struct mixer_context *ctx = crtc->ctx;
+	struct mixer_context *ctx = to_mixer(crtc);
 	int width = mode->hdisplay, height = mode->vdisplay, i;
 
 	struct {
@@ -1117,7 +1119,6 @@ static int mixer_bind(struct device *dev, struct device *manager, void *data)
 {
 	struct mixer_context *ctx = dev_get_drvdata(dev);
 	struct drm_device *drm_dev = data;
-	struct exynos_drm_plane *exynos_plane;
 	unsigned int i;
 	int ret;
 	static enum drm_plane_type types[] = { DRM_PLANE_TYPE_PRIMARY,
@@ -1151,14 +1152,14 @@ static int mixer_bind(struct device *dev, struct device *manager, void *data)
 			return ret;
 	}
 
-	exynos_plane = &ctx->planes[DEFAULT_WIN];
-	ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
-			EXYNOS_DISPLAY_TYPE_HDMI, &mixer_crtc_ops, ctx);
-	if (IS_ERR(ctx->crtc)) {
+	ctx->crtc.type = EXYNOS_DISPLAY_TYPE_HDMI;
+	ctx->crtc.ops = &mixer_crtc_ops;
+	ret = exynos_drm_crtc_init(&ctx->crtc, drm_dev);
+	if (ret) {
 		mixer_ctx_remove(ctx);
-		ret = PTR_ERR(ctx->crtc);
 		goto free_ctx;
 	}
+	ctx->crtc.base.primary = &ctx->planes[DEFAULT_WIN].base;
 
 	return 0;
 
-- 
2.17.1



More information about the dri-devel mailing list