Add rcar_du_lib_mode_cfg_helper_fns() in RCar DU kms lib to get the
pointer to rcar_du_mode_config_helper, so that both rcar_du_atomic_
commit_tail() and rcar_du_mode_config_helper can be reused by
rcar_du_modeset_init() and rzg2l_du_modeset_init().

Signed-off-by: Biju Das <biju.das...@bp.renesas.com>
---
v5:
 * New patch
---
 drivers/gpu/drm/rcar-du/rcar_du_kms.c     | 44 +-----------------
 drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c | 56 +++++++++++++++++++++++
 drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h |  3 ++
 3 files changed, 60 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c 
b/drivers/gpu/drm/rcar-du/rcar_du_kms.c
index 9d65a7d6d96e..ed8d14701178 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c
@@ -64,52 +64,10 @@ static int rcar_du_atomic_check(struct drm_device *dev,
        return rcar_du_atomic_check_planes(dev, state);
 }
 
-static void rcar_du_atomic_commit_tail(struct drm_atomic_state *old_state)
-{
-       struct drm_device *dev = old_state->dev;
-       struct rcar_du_device *rcdu = to_rcar_du_device(dev);
-       struct drm_crtc_state *crtc_state;
-       struct drm_crtc *crtc;
-       unsigned int i;
-
-       /*
-        * Store RGB routing to DPAD0 and DPAD1, the hardware will be configured
-        * when starting the CRTCs.
-        */
-       rcdu->dpad1_source = -1;
-
-       for_each_new_crtc_in_state(old_state, crtc, crtc_state, i) {
-               struct rcar_du_crtc_state *rcrtc_state =
-                       to_rcar_crtc_state(crtc_state);
-               struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
-
-               if (rcrtc_state->outputs & BIT(RCAR_DU_OUTPUT_DPAD0))
-                       rcdu->dpad0_source = rcrtc->index;
-
-               if (rcrtc_state->outputs & BIT(RCAR_DU_OUTPUT_DPAD1))
-                       rcdu->dpad1_source = rcrtc->index;
-       }
-
-       /* Apply the atomic update. */
-       drm_atomic_helper_commit_modeset_disables(dev, old_state);
-       drm_atomic_helper_commit_planes(dev, old_state,
-                                       DRM_PLANE_COMMIT_ACTIVE_ONLY);
-       drm_atomic_helper_commit_modeset_enables(dev, old_state);
-
-       drm_atomic_helper_commit_hw_done(old_state);
-       drm_atomic_helper_wait_for_flip_done(dev, old_state);
-
-       drm_atomic_helper_cleanup_planes(dev, old_state);
-}
-
 /* 
-----------------------------------------------------------------------------
  * Initialization
  */
 
-static const struct drm_mode_config_helper_funcs rcar_du_mode_config_helper = {
-       .atomic_commit_tail = rcar_du_atomic_commit_tail,
-};
-
 static const struct drm_mode_config_funcs rcar_du_mode_config_funcs = {
        .fb_create = rcar_du_fb_create,
        .atomic_check = rcar_du_atomic_check,
@@ -415,7 +373,7 @@ int rcar_du_modeset_init(struct rcar_du_device *rcdu)
        dev->mode_config.min_height = 0;
        dev->mode_config.normalize_zpos = true;
        dev->mode_config.funcs = &rcar_du_mode_config_funcs;
-       dev->mode_config.helper_private = &rcar_du_mode_config_helper;
+       dev->mode_config.helper_private = rcar_du_lib_mode_cfg_helper_fns();
 
        if (rcdu->info->gen < 3) {
                dev->mode_config.max_width = 4095;
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c 
b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c
index d8f778a7b6db..a1027436cfe3 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.c
@@ -461,3 +461,59 @@ rcar_du_lib_fb_create(struct drm_device *dev, struct 
drm_file *file_priv,
 
        return drm_gem_fb_create(dev, file_priv, mode_cmd);
 }
+
+/* 
-----------------------------------------------------------------------------
+ * Atomic Check and Update
+ */
+
+static void rcar_du_atomic_commit_tail(struct drm_atomic_state *old_state)
+{
+       struct drm_device *dev = old_state->dev;
+       struct rcar_du_device *rcdu = to_rcar_du_device(dev);
+       struct drm_crtc_state *crtc_state;
+       struct drm_crtc *crtc;
+       unsigned int i;
+
+       /*
+        * Store RGB routing to DPAD0 and DPAD1, the hardware will be configured
+        * when starting the CRTCs.
+        */
+       rcdu->dpad1_source = -1;
+
+       for_each_new_crtc_in_state(old_state, crtc, crtc_state, i) {
+               struct rcar_du_crtc_state *rcrtc_state =
+                       to_rcar_crtc_state(crtc_state);
+               struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
+
+               if (rcrtc_state->outputs & BIT(RCAR_DU_OUTPUT_DPAD0))
+                       rcdu->dpad0_source = rcrtc->index;
+
+               if (rcrtc_state->outputs & BIT(RCAR_DU_OUTPUT_DPAD1))
+                       rcdu->dpad1_source = rcrtc->index;
+       }
+
+       /* Apply the atomic update. */
+       drm_atomic_helper_commit_modeset_disables(dev, old_state);
+       drm_atomic_helper_commit_planes(dev, old_state,
+                                       DRM_PLANE_COMMIT_ACTIVE_ONLY);
+       drm_atomic_helper_commit_modeset_enables(dev, old_state);
+
+       drm_atomic_helper_commit_hw_done(old_state);
+       drm_atomic_helper_wait_for_flip_done(dev, old_state);
+
+       drm_atomic_helper_cleanup_planes(dev, old_state);
+}
+
+/* 
-----------------------------------------------------------------------------
+ * Initialization
+ */
+
+static const struct drm_mode_config_helper_funcs rcar_du_mode_config_helper = {
+       .atomic_commit_tail = rcar_du_atomic_commit_tail,
+};
+
+const struct drm_mode_config_helper_funcs *
+rcar_du_lib_mode_cfg_helper_fns(void)
+{
+       return &rcar_du_mode_config_helper;
+}
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h 
b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h
index 160928dc68b8..8a689ac6c83f 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h
+++ b/drivers/gpu/drm/rcar-du/rcar_du_kms_lib.h
@@ -43,4 +43,7 @@ struct drm_framebuffer *
 rcar_du_lib_fb_create(struct drm_device *dev, struct drm_file *file_priv,
                      const struct drm_mode_fb_cmd2 *mode_cmd);
 
+const struct drm_mode_config_helper_funcs *
+rcar_du_lib_mode_cfg_helper_fns(void);
+
 #endif /* __RCAR_DU_KMS_LIB_H__ */
-- 
2.25.1

Reply via email to