[PATCH v2 RESEND 07/24] drm/exynos/fimd: embed exynos_drm_crtc directly into context

Andrzej Hajda a.hajda at samsung.com
Wed Mar 20 13:06:50 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_fimd.c | 60 ++++++++++++------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimd.c b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
index 2d34ca375ee1..8ea1cfd51736 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fimd.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
@@ -169,7 +169,7 @@ static struct fimd_driver_data exynos5420_fimd_driver_data = {
 struct fimd_context {
 	struct device			*dev;
 	struct drm_device		*drm_dev;
-	struct exynos_drm_crtc		*crtc;
+	struct exynos_drm_crtc		crtc;
 	struct exynos_drm_plane		planes[WINDOWS_NR];
 	struct clk			*bus_clk;
 	struct clk			*lcd_clk;
@@ -193,6 +193,8 @@ struct fimd_context {
 	struct exynos_drm_clk		dp_clk;
 };
 
+#define to_fimd(ptr) container_of(ptr, struct fimd_context, ptr)
+
 static const struct of_device_id fimd_driver_dt_match[] = {
 	{ .compatible = "samsung,s3c6400-fimd",
 	  .data = &s3c64xx_fimd_driver_data },
@@ -235,7 +237,7 @@ static inline void fimd_set_bits(struct fimd_context *ctx, u32 reg, u32 mask,
 
 static int fimd_enable_vblank(struct exynos_drm_crtc *crtc)
 {
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 	u32 val;
 
 	if (ctx->suspended)
@@ -267,7 +269,7 @@ static int fimd_enable_vblank(struct exynos_drm_crtc *crtc)
 
 static void fimd_disable_vblank(struct exynos_drm_crtc *crtc)
 {
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 	u32 val;
 
 	if (ctx->suspended)
@@ -291,7 +293,7 @@ static void fimd_disable_vblank(struct exynos_drm_crtc *crtc)
 
 static void fimd_wait_for_vblank(struct exynos_drm_crtc *crtc)
 {
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 
 	if (ctx->suspended)
 		return;
@@ -345,7 +347,7 @@ static void fimd_disable_win(struct fimd_context *ctx, int win)
 
 static void fimd_clear_channels(struct exynos_drm_crtc *crtc)
 {
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 	unsigned int win, ch_enabled = 0;
 
 	DRM_DEBUG_KMS("%s\n", __FILE__);
@@ -370,9 +372,9 @@ static void fimd_clear_channels(struct exynos_drm_crtc *crtc)
 	if (ch_enabled) {
 		ctx->suspended = false;
 
-		fimd_enable_vblank(ctx->crtc);
-		fimd_wait_for_vblank(ctx->crtc);
-		fimd_disable_vblank(ctx->crtc);
+		fimd_enable_vblank(&ctx->crtc);
+		fimd_wait_for_vblank(&ctx->crtc);
+		fimd_disable_vblank(&ctx->crtc);
 
 		ctx->suspended = true;
 	}
@@ -388,7 +390,7 @@ static int fimd_atomic_check(struct exynos_drm_crtc *crtc,
 		struct drm_crtc_state *state)
 {
 	struct drm_display_mode *mode = &state->adjusted_mode;
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 	unsigned long ideal_clk, lcd_rate;
 	u32 clkdiv;
 
@@ -448,7 +450,7 @@ static void fimd_setup_trigger(struct fimd_context *ctx)
 
 static void fimd_commit(struct exynos_drm_crtc *crtc)
 {
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 	struct drm_display_mode *mode = &crtc->base.state->adjusted_mode;
 	const struct fimd_driver_data *driver_data = ctx->driver_data;
 	void *timing_base = ctx->regs + driver_data->timing_base;
@@ -754,7 +756,7 @@ static void fimd_shadow_protect_win(struct fimd_context *ctx,
 
 static void fimd_atomic_begin(struct exynos_drm_crtc *crtc)
 {
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 	int i;
 
 	if (ctx->suspended)
@@ -766,7 +768,7 @@ static void fimd_atomic_begin(struct exynos_drm_crtc *crtc)
 
 static void fimd_atomic_flush(struct exynos_drm_crtc *crtc)
 {
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 	int i;
 
 	if (ctx->suspended)
@@ -789,7 +791,7 @@ static void fimd_update_plane(struct exynos_drm_crtc *crtc,
 {
 	struct exynos_drm_plane_state *state =
 				to_exynos_plane_state(plane->base.state);
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 	struct drm_framebuffer *fb = state->base.fb;
 	dma_addr_t dma_addr;
 	unsigned long val, size, offset;
@@ -878,7 +880,7 @@ static void fimd_update_plane(struct exynos_drm_crtc *crtc,
 
 static void fimd_enable(struct exynos_drm_crtc *crtc)
 {
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 
 	if (!ctx->suspended)
 		return;
@@ -889,14 +891,14 @@ static void fimd_enable(struct exynos_drm_crtc *crtc)
 
 	/* if vblank was enabled status, enable it again. */
 	if (test_and_clear_bit(0, &ctx->irq_flags))
-		fimd_enable_vblank(ctx->crtc);
+		fimd_enable_vblank(&ctx->crtc);
 
-	fimd_commit(ctx->crtc);
+	fimd_commit(&ctx->crtc);
 }
 
 static void fimd_disable(struct exynos_drm_crtc *crtc)
 {
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 	int i;
 
 	if (ctx->suspended)
@@ -951,7 +953,7 @@ static void fimd_trigger(struct device *dev)
 
 static void fimd_te_handler(struct exynos_drm_crtc *crtc)
 {
-	struct fimd_context *ctx = crtc->ctx;
+	struct fimd_context *ctx = to_fimd(crtc);
 	u32 trg_type = ctx->driver_data->trg_type;
 
 	/* Checks the crtc is detached already from encoder */
@@ -976,7 +978,7 @@ static void fimd_te_handler(struct exynos_drm_crtc *crtc)
 	}
 
 	if (test_bit(0, &ctx->irq_flags))
-		drm_crtc_handle_vblank(&ctx->crtc->base);
+		drm_crtc_handle_vblank(&ctx->crtc.base);
 }
 
 static void fimd_dp_clock_enable(struct exynos_drm_clk *clk, bool enable)
@@ -1015,7 +1017,7 @@ static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
 		goto out;
 
 	if (!ctx->i80_if)
-		drm_crtc_handle_vblank(&ctx->crtc->base);
+		drm_crtc_handle_vblank(&ctx->crtc.base);
 
 	if (ctx->i80_if) {
 		/* Exits triggering mode */
@@ -1036,7 +1038,6 @@ static int fimd_bind(struct device *dev, struct device *master, void *data)
 {
 	struct fimd_context *ctx = dev_get_drvdata(dev);
 	struct drm_device *drm_dev = data;
-	struct exynos_drm_plane *exynos_plane;
 	unsigned int i;
 	int ret;
 
@@ -1053,22 +1054,23 @@ static int fimd_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_LCD, &fimd_crtc_ops, ctx);
-	if (IS_ERR(ctx->crtc))
-		return PTR_ERR(ctx->crtc);
+	ctx->crtc.type = EXYNOS_DISPLAY_TYPE_LCD;
+	ctx->crtc.ops = &fimd_crtc_ops;
+	ret = exynos_drm_crtc_init(&ctx->crtc, drm_dev);
+	if (ret)
+		return ret;
+	ctx->crtc.base.primary = &ctx->planes[DEFAULT_WIN].base;
 
 	if (ctx->driver_data->has_dp_clk) {
 		ctx->dp_clk.enable = fimd_dp_clock_enable;
-		ctx->crtc->pipe_clk = &ctx->dp_clk;
+		ctx->crtc.pipe_clk = &ctx->dp_clk;
 	}
 
 	if (ctx->encoder)
 		exynos_dpi_bind(drm_dev, ctx->encoder);
 
 	if (is_drm_iommu_supported(drm_dev))
-		fimd_clear_channels(ctx->crtc);
+		fimd_clear_channels(&ctx->crtc);
 
 	return exynos_drm_register_dma(drm_dev, dev);
 }
@@ -1078,7 +1080,7 @@ static void fimd_unbind(struct device *dev, struct device *master,
 {
 	struct fimd_context *ctx = dev_get_drvdata(dev);
 
-	fimd_disable(ctx->crtc);
+	fimd_disable(&ctx->crtc);
 
 	exynos_drm_unregister_dma(ctx->drm_dev, ctx->dev);
 
-- 
2.17.1



More information about the dri-devel mailing list