sti_hqvdp_atomic_check() enables the main pixel clock and registers the
VTG vsync notifier.

.atomic_check() must not touch the hardware.  A commit with
DRM_MODE_ATOMIC_TEST_ONLY only runs the check hooks, and a commit that
fails a later check is dropped, so either way the clock is left enabled
and the notifier registered for a configuration that was never applied.

Neither of the two belongs in device init.  sti_vtg_register_client()
stores the CRTC the plane is attached to, which a commit provides and
device init does not, and the clock enable is undone by the matching
clk_disable_unprepare() in sti_hqvdp_disable(), so it follows the
streaming lifetime rather than the device lifetime.  Move both to
.atomic_update(), where sti_gdp already registers its own VTG client the
same way.

The failure paths can no longer reject the commit, so they are logged
once and the plane is left alone.

Fixes: dd86dc2f9ae1 ("drm/sti: implement atomic_check for the planes")
Signed-off-by: Minseo Park <[email protected]>
---
 drivers/gpu/drm/sti/sti_hqvdp.c | 37 +++++++++++++++++----------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/sti/sti_hqvdp.c b/drivers/gpu/drm/sti/sti_hqvdp.c
index c6b6ed54b899..17c7f5a7854c 100644
--- a/drivers/gpu/drm/sti/sti_hqvdp.c
+++ b/drivers/gpu/drm/sti/sti_hqvdp.c
@@ -1081,24 +1081,6 @@ static int sti_hqvdp_atomic_check(struct drm_plane 
*drm_plane,
                return -EINVAL;
        }
 
-       if (!hqvdp->vtg_registered) {
-               /* Prevent VTG shutdown */
-               if (clk_prepare_enable(hqvdp->clk_pix_main)) {
-                       DRM_ERROR("Failed to prepare/enable pix main clk\n");
-                       return -EINVAL;
-               }
-
-               /* Register VTG Vsync callback to handle bottom fields */
-               if (sti_vtg_register_client(hqvdp->vtg,
-                                           &hqvdp->vtg_nb,
-                                           crtc)) {
-                       DRM_ERROR("Cannot register VTG notifier\n");
-                       clk_disable_unprepare(hqvdp->clk_pix_main);
-                       return -EINVAL;
-               }
-               hqvdp->vtg_registered = true;
-       }
-
        DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n",
                      crtc->base.id, sti_mixer_to_str(to_sti_mixer(crtc)),
                      drm_plane->base.id, sti_plane_to_str(plane));
@@ -1148,6 +1130,25 @@ static void sti_hqvdp_atomic_update(struct drm_plane 
*drm_plane,
        }
 
        mode = &crtc->mode;
+
+       if (!hqvdp->vtg_registered) {
+               /* Prevent VTG shutdown */
+               if (clk_prepare_enable(hqvdp->clk_pix_main)) {
+                       drm_err_once(drm_plane->dev,
+                                    "Failed to prepare/enable pix main clk\n");
+                       return;
+               }
+
+               /* Register VTG Vsync callback to handle bottom fields */
+               if (sti_vtg_register_client(hqvdp->vtg, &hqvdp->vtg_nb, crtc)) {
+                       drm_err_once(drm_plane->dev,
+                                    "Cannot register VTG notifier\n");
+                       clk_disable_unprepare(hqvdp->clk_pix_main);
+                       return;
+               }
+               hqvdp->vtg_registered = true;
+       }
+
        dst_x = newstate->crtc_x;
        dst_y = newstate->crtc_y;
        dst_w = clamp_val(newstate->crtc_w, 0, mode->hdisplay - dst_x);
-- 
2.43.0

Reply via email to