The mediatek crtc implementation provides a custom reset hook.
However, this hook only allocates the state, initializes it with
__drm_atomic_helper_crtc_reset(), and frees the previous state. It
does not perform any hardware reset.

Since this is exactly what the atomic_create_state hook is meant to
do, minus the old state cleanup which the caller handles, convert the
implementation to use atomic_create_state with
__drm_atomic_helper_crtc_state_init() instead.

Signed-off-by: Maxime Ripard <[email protected]>
---
Cc: AngeloGioacchino Del Regno <[email protected]>
Cc: Chun-Kuang Hu <[email protected]>
Cc: Matthias Brugger <[email protected]>
Cc: Philipp Zabel <[email protected]>
---
 drivers/gpu/drm/mediatek/mtk_crtc.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c 
b/drivers/gpu/drm/mediatek/mtk_crtc.c
index 8e552cdc3b53..fd4b19efee52 100644
--- a/drivers/gpu/drm/mediatek/mtk_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
@@ -148,23 +148,21 @@ static void mtk_crtc_destroy(struct drm_crtc *crtc)
        }
 
        drm_crtc_cleanup(crtc);
 }
 
-static void mtk_crtc_reset(struct drm_crtc *crtc)
+static struct drm_crtc_state *mtk_crtc_create_state(struct drm_crtc *crtc)
 {
        struct mtk_crtc_state *state;
 
-       if (crtc->state)
-               __drm_atomic_helper_crtc_destroy_state(crtc->state);
-
-       kfree(to_mtk_crtc_state(crtc->state));
-       crtc->state = NULL;
-
        state = kzalloc_obj(*state);
-       if (state)
-               __drm_atomic_helper_crtc_reset(crtc, &state->base);
+       if (!state)
+               return ERR_PTR(-ENOMEM);
+
+       __drm_atomic_helper_crtc_state_init(&state->base, crtc);
+
+       return &state->base;
 }
 
 static struct drm_crtc_state *mtk_crtc_duplicate_state(struct drm_crtc *crtc)
 {
        struct mtk_crtc_state *state;
@@ -884,11 +882,11 @@ static void mtk_crtc_atomic_flush(struct drm_crtc *crtc,
 
 static const struct drm_crtc_funcs mtk_crtc_funcs = {
        .set_config             = drm_atomic_helper_set_config,
        .page_flip              = drm_atomic_helper_page_flip,
        .destroy                = mtk_crtc_destroy,
-       .reset                  = mtk_crtc_reset,
+       .atomic_create_state = mtk_crtc_create_state,
        .atomic_duplicate_state = mtk_crtc_duplicate_state,
        .atomic_destroy_state   = mtk_crtc_destroy_state,
        .enable_vblank          = mtk_crtc_enable_vblank,
        .disable_vblank         = mtk_crtc_disable_vblank,
 };

-- 
2.55.0

Reply via email to