[PATCH] media: xilinx: vtc: Dynamically calculate pixel clock

Gugulothu, Rajesh rajesh.gugulothu at amd.com
Tue Sep 1 02:36:58 PDT 2026


AMD General

Hi All,

A gentle reminder on this patch. When you have a chance, could you please review it and let me know if any changes are needed?

Thanks,
Rajesh G

>-----Original Message-----
>From: Rajesh Gugulothu <rajesh.gugulothu at amd.com>
>Sent: Wednesday, July 29, 2026 3:48 PM
>To: Laurent Pinchart <laurent.pinchart at ideasonboard.com>; Mauro Carvalho
>Chehab <mchehab at kernel.org>; Simek, Michal <michal.simek at amd.com>
>Cc: Gugulothu, Rajesh <rajesh.gugulothu at amd.com>; linux-media at vger.kernel.org;
>linux-arm-kernel at lists.infradead.org; linux-kernel at vger.kernel.org
>Subject: [PATCH] media: xilinx: vtc: Dynamically calculate pixel clock
>
>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 at 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);
>--
>2.34.1




More information about the linux-arm-kernel mailing list