From: Minseo Park <hiyoukou@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: tzimmermann@suse.de, alain.volmat@foss.st.com,
rgallaispou@gmail.com, maarten.lankhorst@linux.intel.com,
mripard@kernel.org, airlied@gmail.com, simona@ffwll.ch,
benjamin.gaignard@collabora.com, Minseo Park <hiyoukou@gmail.com>
Subject: [PATCH v2 2/4] drm/sti: gdp: set the pixel clock from .atomic_update()
Date: Thu, 26 Nov 2026 11:47:08 +0900 [thread overview]
Message-ID: <20261126024710.33401-3-hiyoukou@gmail.com> (raw)
In-Reply-To: <20261126024710.33401-1-hiyoukou@gmail.com>
sti_gdp_atomic_check() reparents the GDP pixel clock and calls
clk_set_rate() on it with the clock of the mode being checked.
.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 in both cases the clock of a mode
that was never applied is programmed on a display that is still scanning
out the previous one.
Move the clock setup to .atomic_update(), where the rest of the plane is
programmed. A clk_set_rate() failure can no longer reject the commit, so
it is logged once and the plane is left as it was.
The check still rejects a mode the clock cannot reach. clk_round_rate()
reports the rate that would be selected without touching the hardware,
which is how the connectors already validate their own pixel clocks in
.mode_valid(). It rounds against the parent that is selected now, so the
check is skipped when this commit would reparent the clock.
Fixes: dd86dc2f9ae1 ("drm/sti: implement atomic_check for the planes")
Signed-off-by: Minseo Park <hiyoukou@gmail.com>
---
drivers/gpu/drm/sti/sti_gdp.c | 73 ++++++++++++++++++++++++-----------
1 file changed, 51 insertions(+), 22 deletions(-)
diff --git a/drivers/gpu/drm/sti/sti_gdp.c b/drivers/gpu/drm/sti/sti_gdp.c
index d0c886029c57..4a01bc64f4ab 100644
--- a/drivers/gpu/drm/sti/sti_gdp.c
+++ b/drivers/gpu/drm/sti/sti_gdp.c
@@ -6,6 +6,7 @@
* for STMicroelectronics.
*/
+#include <linux/clk.h>
#include <linux/dma-mapping.h>
#include <linux/of.h>
#include <linux/seq_file.h>
@@ -28,6 +29,9 @@
#define BIGNOTLITTLE BIT(23)
#define WAIT_NEXT_VSYNC BIT(31)
+/* Same tolerance as the connectors use in their .mode_valid() */
+#define CLK_TOLERANCE_HZ 50
+
/* GDP color formats */
#define GDP_RGB565 0x00
#define GDP_RGB888 0x01
@@ -667,29 +671,28 @@ static int sti_gdp_atomic_check(struct drm_plane *drm_plane,
return -EINVAL;
}
- /* Set gdp clock */
+ /*
+ * The pixel clock is programmed from .atomic_update(). clk_round_rate()
+ * reports the rate that would be selected without touching the
+ * hardware, so the mode can still be rejected here -- but it rounds
+ * against the parent that is selected now, so only rely on it when
+ * this commit is not going to reparent the clock.
+ */
if (mode->clock && gdp->clk_pix) {
- struct clk *clkp;
- int rate = mode->clock * 1000;
- int res;
-
- /*
- * According to the mixer used, the gdp pixel clock
- * should have a different parent clock.
- */
- if (mixer->id == STI_MIXER_MAIN)
- clkp = gdp->clk_main_parent;
- else
- clkp = gdp->clk_aux_parent;
-
- if (clkp)
- clk_set_parent(gdp->clk_pix, clkp);
-
- res = clk_set_rate(gdp->clk_pix, rate);
- if (res < 0) {
- DRM_ERROR("Cannot set rate (%dHz) for gdp\n",
- rate);
- return -EINVAL;
+ struct clk *clkp = mixer->id == STI_MIXER_MAIN ?
+ gdp->clk_main_parent : gdp->clk_aux_parent;
+ int target = mode->clock * 1000;
+ long rounded;
+
+ if (!clkp || clk_is_match(clk_get_parent(gdp->clk_pix), clkp)) {
+ rounded = clk_round_rate(gdp->clk_pix, target);
+ if (rounded < target - CLK_TOLERANCE_HZ ||
+ rounded > target + CLK_TOLERANCE_HZ) {
+ drm_dbg_kms(drm_plane->dev,
+ "gdp pixclk=%d not supported\n",
+ target);
+ return -EINVAL;
+ }
}
}
@@ -757,6 +760,32 @@ static void sti_gdp_atomic_update(struct drm_plane *drm_plane,
}
mode = &crtc->mode;
+
+ /* Set gdp clock */
+ if (mode->clock && gdp->clk_pix) {
+ struct sti_mixer *mixer = to_sti_mixer(crtc);
+ int rate = mode->clock * 1000;
+ struct clk *clkp;
+
+ /*
+ * According to the mixer used, the gdp pixel clock
+ * should have a different parent clock.
+ */
+ if (mixer->id == STI_MIXER_MAIN)
+ clkp = gdp->clk_main_parent;
+ else
+ clkp = gdp->clk_aux_parent;
+
+ if (clkp)
+ clk_set_parent(gdp->clk_pix, clkp);
+
+ if (clk_set_rate(gdp->clk_pix, rate) < 0) {
+ drm_err_once(drm_plane->dev,
+ "Cannot set rate (%dHz) for gdp\n", rate);
+ return;
+ }
+ }
+
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
next prev parent reply other threads:[~2026-11-26 8:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 2:47 [PATCH v2 0/4] drm/sti: move commit work out of .atomic_check() Minseo Park
2026-11-26 2:47 ` [PATCH v2 1/4] drm/sti: cursor: do not resize the pixmap from .atomic_check() Minseo Park
2026-11-26 8:32 ` sashiko-bot
2026-11-26 2:47 ` Minseo Park [this message]
2026-11-26 8:35 ` [PATCH v2 2/4] drm/sti: gdp: set the pixel clock from .atomic_update() sashiko-bot
2026-11-26 2:47 ` [PATCH v2 3/4] drm/sti: hqvdp: start the XP70 from device init Minseo Park
2026-11-26 8:34 ` sashiko-bot
2026-11-26 2:47 ` [PATCH v2 4/4] drm/sti: hqvdp: register the VTG client from .atomic_update() Minseo Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126024710.33401-3-hiyoukou@gmail.com \
--to=hiyoukou@gmail.com \
--cc=airlied@gmail.com \
--cc=alain.volmat@foss.st.com \
--cc=benjamin.gaignard@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=rgallaispou@gmail.com \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.