From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
To: Rajesh Gugulothu <rajesh.gugulothu@amd.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Michal Simek <michal.simek@amd.com>
Cc: linux-media@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Mauro Carvalho Chehab <mchehab@kernel.org>
Subject: Re: [PATCH] media: xilinx: vtc: Dynamically calculate pixel clock
Date: Thu, 3 Sep 2026 13:07:45 +0300 [thread overview]
Message-ID: <bfdf98d4-e3f3-42ff-a0b4-55c67790e4d0@ideasonboard.com> (raw)
In-Reply-To: <20260729101808.3904212-1-rajesh.gugulothu@amd.com>
Hi,
On 29/07/2026 13:18, Rajesh Gugulothu wrote:
> This update enables the vtc to set the pixel clock based on the
> specified timing parameters. A new fps field is added to struct
> xvtc_config and the pixel rate is computed as fps * hsize * vsize.
> After setting the rate, the actual clock rate is read back and a
> warning is emitted if it deviates beyond a small tolerance.
>
> The pixel rate is computed in unsigned long arithmetic to avoid a 32-bit
> overflow in the fps * hsize * vsize product.
>
> Signed-off-by: Rajesh Gugulothu <rajesh.gugulothu@amd.com>
> ---
> drivers/media/platform/xilinx/xilinx-vtc.c | 19 +++++++++++++++++++
> drivers/media/platform/xilinx/xilinx-vtc.h | 1 +
> 2 files changed, 20 insertions(+)
>
> diff --git a/drivers/media/platform/xilinx/xilinx-vtc.c b/drivers/media/platform/xilinx/xilinx-vtc.c
> index 92fec7bb4..695eb2a46 100644
> --- a/drivers/media/platform/xilinx/xilinx-vtc.c
> +++ b/drivers/media/platform/xilinx/xilinx-vtc.c
> @@ -141,6 +141,9 @@
>
> #define XVTC_GENERATOR_GLOBAL_DELAY 0x0104
>
> +/* Value of 1 = .01% */
> +#define XVTC_CLK_MAX_PCT_ERR 1
> +
> /**
> * struct xvtc_device - Xilinx Video Timing Controller device structure
> * @xvip: Xilinx Video IP device
> @@ -175,10 +178,26 @@ int xvtc_generator_start(struct xvtc_device *xvtc,
> const struct xvtc_config *config)
> {
> int ret;
> + unsigned long s_rate;
> + unsigned long g_rate;
> + unsigned long clk_err;
>
> if (!xvtc->has_generator)
> return -ENXIO;
>
> + s_rate = (unsigned long)config->fps * config->hsize * config->vsize;
> + ret = clk_set_rate(xvtc->xvip.clk, s_rate);
> + if (ret < 0)
> + return ret;
> +
> + /* Verify that the clock is within a reasonable tolerance. */
> + g_rate = clk_get_rate(xvtc->xvip.clk);
> + clk_err = (abs(g_rate - s_rate) * 10000) / (s_rate);
> + if (clk_err > XVTC_CLK_MAX_PCT_ERR)
> + dev_warn(xvtc->xvip.dev,
> + "Failed to set clk rate: %lu, actual rate: %lu\n",
> + s_rate, g_rate);
> +
> ret = clk_prepare_enable(xvtc->xvip.clk);
> if (ret < 0)
> return ret;
> diff --git a/drivers/media/platform/xilinx/xilinx-vtc.h b/drivers/media/platform/xilinx/xilinx-vtc.h
> index 855845911..0f360ed55 100644
> --- a/drivers/media/platform/xilinx/xilinx-vtc.h
> +++ b/drivers/media/platform/xilinx/xilinx-vtc.h
> @@ -27,6 +27,7 @@ struct xvtc_config {
> unsigned int vsync_start;
> unsigned int vsync_end;
> unsigned int vsize;
> + unsigned int fps;
> };
>
> struct xvtc_device *xvtc_of_get(struct device_node *np);
In upstream there's a single user for the VTC: the TPG driver. It
doesn't set the fps field, so the above code would always try to set the
rate to 0, wouldn't it?
What is "reasonable tolerance", why did you arrive to .01%? Also, the
actual result is not visible to the user.
I think this is a slightly bigger topic than a single VTC patch. There
should be a userspace API to set the FPS, and the user should see what
was the actual rate he got via the API (instead of a dev_warn when the
rate is off more than an arbitrary tolerance).
Tomi
prev parent reply other threads:[~2026-09-03 10:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 10:18 [PATCH] media: xilinx: vtc: Dynamically calculate pixel clock Rajesh Gugulothu
2026-09-01 9:36 ` Gugulothu, Rajesh
2026-09-01 11:56 ` Laurent Pinchart
2026-09-03 10:07 ` Tomi Valkeinen [this message]
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=bfdf98d4-e3f3-42ff-a0b4-55c67790e4d0@ideasonboard.com \
--to=tomi.valkeinen@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=michal.simek@amd.com \
--cc=rajesh.gugulothu@amd.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox